A lot of time my lists are too big tor process and i have to break them up into batches to process.
Is there a way to encapsulate this in a method or an extension. I seem to have to write this batching logic everywhere.
const int TAKE = 100;
int skip = 0;
while (skip < contacts.Count)
{
var batch = contacts.Skip(skip).Take(TAKE).ToList();
DoSomething(batch);
skip += TAKE;
}
I would like to do something like -
Batch(contacts, DoSomething);
Or anything similar so i do not have to write this batching logic again and again.