using System.Collections.Generic;
public static void Main()
var emptyData = Enumerable.Empty<int>();
var data = Enumerable.Range(1, 100);
Console.WriteLine($"{nameof(emptyData)}:");
Console.WriteLine(FormatResults(emptyData, 2));
Console.WriteLine($"{nameof(data)}:");
Console.WriteLine(FormatResults(data, 13));
private static string FormatResults<T>(IEnumerable<T> data, int partitionSize)
return string.Join($",{Environment.NewLine}", data.Partition(partitionSize).Select(i => $"( {string.Join(", ", i)} )"));
public static IEnumerable<IList<T>> Partition<T>(
this IEnumerable<T> source,
throw new ArgumentOutOfRangeException(
"Must be greater or equal to 2.");
using (var e = source.GetEnumerator())
partition[0] = e.Current;
partition[count] = e.Current;
Array.Resize(ref partition, count);