title: Create Batches from Object collection
body: <p>I have a collection of objects (more than 500 in count)
  I would like to batch it with some logic, like a batch of 50's and I should get 10 sets.(10*50=500)</p>
  
  <p>I am using the logic below:</p>
  
  <pre><code> public class CustomEngineReader :IEnumerable&lt;List&lt;EngineToken&gt;&gt;
  {
      StreamReader sr;
      int _batchSize = 1;
  
      public CustomFileReader(List&lt;EngineToken&gt; tokens, int batchSize)
      {
          if (batchSize &gt; 0)
          {
              _batchSize = batchSize;
          }
  
  
  
      }
  
  
      public IEnumerator&lt;List&lt;string&gt;&gt; GetEnumerator()
      {
  
          string input = string.Empty;
  
          foreach(var item in EngineTokens)
          {
              int i = 0;
              List&lt;string&gt; batch = new List&lt;string&gt;();
  
              while (i &lt; _batchSize &amp;&amp; item !=null)
              {
                  batch.Add(item );
                  i++;
              }
  
              if (batch.Count != 0)
              {
                  yield return batch;
              }
          }
  
      }
  
      IEnumerator IEnumerable.GetEnumerator()
      {
          return GetEnumerator();
      }
  }
  </code></pre>
  
  <p>I am using the above code as below</p>
  
  <pre><code>CustomEngineReader reader = new CustomEngineReader (this.tokencollection, 50);
  foreach(List&lt;EngineToken&gt; items in reader)
  {
         //in each iteration we get batch specified objects
         foreach(EngineToken item in items)
         {
            //Process
         }    
  }
  </code></pre>
  
  <p>It's not working.</p>