title: Creating an anonymous object, how to use a loop to add items
body: <p>I'm currently creating a anonymous object like this, it works fine so far.</p>
  
  <pre><code>var users = new
  {
     action = "users",
     newbies = new[]
     {
        new
        {
           email = "abc",
           username = "def",
           location = "ghi"
        }
     }
  }
  </code></pre>
  
  <p>Now I need to modify this, by adding more properties to the inner object.<br>
  I have a List that has users in it, which represents the users friends.</p>
  
  <pre><code>List&lt;User&gt; friends = ...
  </code></pre>
  
  <p>So the inner object should look something like:</p>
  
  <p>new</p>
  
  <pre><code>{
    email = "abc",
    username = "def",
    location = "ghi",
    friend1email = "f1@example.com",
    friend2username = "f1",
    friend2email = "f2@example.com",
    friend2username = "f2",
  }
  </code></pre>
  
  <p>except I would need to get this using the LIst, so looping like:</p>
  
  <pre><code>foreach(var user in friends)
  {
  
  }
  </code></pre>
  
  <p>How can I generate this type of a anonymous object when I need to loop?</p>
  
  <p>Note:  I can't change the format here, I know it is silly but that is how it is.</p>
  
  <p>Update</p>
  
  <p><strong>How can I do this using the ExpandoObject?</strong></p>