title: How to create a list using foreach - C#
body: <p>I have this class :</p>
  
  <pre><code>public class JsonObj
  {
      public string name { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;JsonObj&gt; children { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public int? size { get; set; }
  
  }
  </code></pre>
  
  <p>And also this class and a list of the class' objects</p>
  
  <pre><code>public class MyObj
  {
    public string Name {get; set;}
    public int Number {get; set;}
  }
  </code></pre>
  
  <p>And suppose <code>myList</code> has a number objects of <code>MyObj</code>.</p>
  
  <p>Now I'm trying to create a big JsonObj whose children are myList members. That's what I have done so far : </p>
  
  <pre><code>var root = new JsonObj
  {
     name = "ROOT",
     children = new List&lt;JsonObj&gt;()
     {
       //I suppose I need to use foreach here, but I don't know how to do it.
     }
  };
  </code></pre>
  
  <p>How can I create objects using a loop for that list here? Thanks.</p>