C# Split IEnumerable in groups by size (chunks)

Date: 2021-03-31
public static IEnumerable<IEnumerable<T>> Split<T>(IEnumerable<T> src, int size) 
            => src.Where((x, i) => i % size == 0).Select((x, i) => src.Skip(i * size).Take(size));

// usage:
var data = new string[,] {
	{ "Huidig snipper-saldo", FormatNumber(info.SaldoNow) },
	{ "Huidig tijd-voor-tijd saldo", FormatNumber(info.SaldoTVT) },
	{ "Saldo totaal dit jaar", FormatNumber(info.SaldoTotalThisYear) }
};
var enumerable = Split(data.Cast<string>(), 2);
48150cookie-checkC# Split IEnumerable in groups by size (chunks)