title: Passing an anonymous object as an argument in C#
body: <p>I have a problem with passing an anonymous object as an argument in a method. I want to pass the object like in JavaScript. Example:</p>
  
  <pre><code>function Test(obj) {
      return obj.txt;
  }
  console.log(Test({ txt: "test"}));
  </code></pre>
  
  <p>But in C#, it throws many exceptions:</p>
  
  <pre><code>class Test
  {
      public static string TestMethod(IEnumerable&lt;dynamic&gt; obj)
      {
          return obj.txt;
      }
  }
  Console.WriteLine(Test.TestMethod(new { txt = "test" }));
  </code></pre>
  
  <p>Exceptions:</p>
  
  <ol>
  <li>Argument 1: cannot convert from 'AnonymousType#1' to
  'System.Collections.Generic.IEnumerable'</li>
  <li>The best overloaded method match for
  'ConsoleApplication1.Test.TestMethod(System.Collections.Generic.IEnumerable)'
  has some invalid arguments</li>
  <li>'System.Collections.Generic.IEnumerable' does not contain a
  definition for 'txt' and no extension method 'txt' accepting a first
  argument of type 'System.Collections.Generic.IEnumerable'
  could be found (are you missing a using directive or an assembly
  reference?)</li>
  </ol>