using System.Collections.Generic;
public static void Main()
List<int> ages = new List<int>(){1,2,3,4,5,6,7,8,9,10};
var batchedAges = ages.Batch(2);
var test = batchedAges.ToList();
public static IEnumerable<List<TSource>> Batch<TSource>(this IEnumerable<TSource> source, int size)
List<TSource> bucket = null;
foreach (TSource item in source)
bucket = new List<TSource>(size);
if (bucket != null && count > 0)
yield return bucket.Take(count).ToList();