title: Split an IEnumerable<T> into fixed-sized chunks (return an IEnumerable<IEnumerable<T>> where the inner sequences are of fixed length)
body: <p>I want to take an <code>IEnumerable&lt;T&gt;</code> and split it up into fixed-sized chunks.</p>
  
  <p>I have this, but it seems inelegant due to all the list creation/copying:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; Partition&lt;T&gt;(this IEnumerable&lt;T&gt; items, int partitionSize)
  {
      List&lt;T&gt; partition = new List&lt;T&gt;(partitionSize);
      foreach (T item in items)
      {
          partition.Add(item);
          if (partition.Count == partitionSize)
          {
              yield return partition;
              partition = new List&lt;T&gt;(partitionSize);
          }
      }
      // Cope with items.Count % partitionSize != 0
      if (partition.Count &gt; 0) yield return partition;
  }
  </code></pre>
  
  <p>Is there something more idiomatic?</p>
  
  <p>EDIT: Although this has been marked as a duplicate of <a href="https://stackoverflow.com/questions/3210824/divide-array-into-an-array-of-subsequence-array">Divide array into an array of subsequence array</a> it is not - that question deals with splitting an array, whereas this is about <code>IEnumerable&lt;T&gt;</code>. In addition that question requires that the last subsequence is padded. The two questions are closely related but aren't the same.</p>