Exemple #1
0
 /// <summary>
 /// Partitions the sequence of elements into groups of fixed size.
 /// </summary>
 /// <typeparam name="T">The type of elements in the sequence.</typeparam>
 /// <param name="source">The sequence to partition.</param>
 /// <param name="partitionSize">The number of elements in group.</param>
 /// <returns>The sequence of partitions.</returns>
 public static IEnumerable <List <T> > Partition <T>(IEnumerable <T> source, int partitionSize)
 {
     using (IEnumerator <T> enumerator = source.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             List <T> partition = Partitioner.YieldPartition(enumerator, partitionSize);
             if (partition.Count > 0)
             {
                 yield return(partition);
             }
         }
     }
 }