How to spilt a collection into sub collections of a certain size in .NET 6+ using the LINQ Chunk method

FYI, in .NET 6+ the Chunk LINQ method is useful for splitting up sequences into sub sequences of a certain size …

Of course many of us have written code manually to do this over the years but having it built into .NET 6 means we can now ditch our own custom code.

An example of when we might use Chunk is to batch SQL Statements. SQL Server has a parameter limit of 2100 for example so here we could use Chunk to break up our statements into batches of 500.

Leave a Reply

Your email address will not be published. Required fields are marked *