using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Disco { public static class EnumerableExtensions { public static IEnumerable> Chunk(this IEnumerable source, int ChunkSize) { List buffer = new List(ChunkSize); foreach (var item in source) { buffer.Add(item); if (buffer.Count == ChunkSize) { yield return buffer; buffer = new List(); } } // Return any additional items if (buffer.Count > 0) yield return buffer; } } }