{"id":3974,"date":"2014-03-30T06:49:42","date_gmt":"2014-03-30T06:49:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dynamic-object-problem-with-linq-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:49:42","modified_gmt":"2014-03-30T06:49:42","slug":"dynamic-object-problem-with-linq-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dynamic-object-problem-with-linq-collection-of-common-programming-errors\/","title":{"rendered":"dynamic object problem with linq-Collection of common programming errors"},"content":{"rendered":"<p>When i run the following code :<\/p>\n<pre><code>var aList = new List{\"a\", \"b\", \"c\"};\ndynamic a = aList.Where(item =&gt; item.StartsWith(\"a\"));\ndynamic b = a.Count();\n<\/code><\/pre>\n<p>Microsoft.CSharp.RuntimeBinder.RunTimeBinderException raises.<\/p>\n<p>But when I write a code snippet like this:<\/p>\n<pre><code>public interface IInterface\n{\n}\n\npublic class InterfaceImplementor:IInterface\n{\n    public int ID = 10;\n    public static IInterface Execute()\n    {\n        return new InterfaceImplementor();\n    }\n}\n\npublic class MyClass\n{\n    public static void Main()\n    {\n        dynamic x = InterfaceImplementor.Execute();\n        Console.WriteLine(x.ID);\n    }\n}\n<\/code><\/pre>\n<p>it&#8217;s work.<\/p>\n<p>Why first code snippet doesn&#8217;t work?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When i run the following code : var aList = new List{&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;}; dynamic a = aList.Where(item =&gt; item.StartsWith(&#8220;a&#8221;)); dynamic b = a.Count(); Microsoft.CSharp.RuntimeBinder.RunTimeBinderException raises. But when I write a code snippet like this: public interface IInterface { } public class InterfaceImplementor:IInterface { public int ID = 10; public static IInterface Execute() { return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3974","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3974"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3974\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}