title: Creating N objects and adding them to a list
body: <p>I have a method which takes in N, the number of objects I want to create, and I need to return a list of N objects.</p>
  
  <p>Currently I can do this with a simple loop:</p>
  
  <pre><code>    private static IEnumerable&lt;MyObj&gt; Create(int count, string foo)
      {
          var myList = new List&lt;MyObj&gt;();
  
          for (var i = 0; i &lt; count; i++)
          {
              myList .Add(new MyObj
                  {
                      bar = foo
                  });
          }
  
          return myList;
      }
  </code></pre>
  
  <p>And I'm wondering if there is another way, maybe with LINQ to create this list.</p>
  
  <p>I've tried:</p>
  
  <pre><code>    private static IEnumerable&lt;MyObj&gt; CreatePaxPriceTypes(int count, string foo)
      {
          var myList = new List&lt;MyObj&gt;(count);
  
          return myList.Select(x =&gt; x = new MyObj
              {
                  bar = foo
              });
  
      }
  </code></pre>
  
  <p>But this does seem to populate my list.</p>
  
  <p>I tried changing the select to a foreach but its the same deal.  </p>
  
  <p>I realized that the list has the <em>capacity</em> of count and LINQ is not finding any elements to iterate.</p>
  
  <pre><code>        myList.ForEach(x =&gt; x = new MyObj
          {
              bar = foo
          });
  </code></pre>
  
  <p>Is there a correct LINQ operator to use to get this to work? Or should I just stick with the loop?</p>