The Problem: You need to process a list of 10,000 items in batches of 100, but writing the for loop math is tedious and error-prone.
The Fix: Since .NET 6, you can simply use LINQ’s .Chunk().
var heavyItems = GetHugeList();
// Instantly splits into arrays of 100 items
foreach (var batch in heavyItems.Chunk(100))
{
ProcessBatch(batch);
}
