Accepted answer

it groups the items into the number of parts that you specify. the i++ will increment for each item and apply the modulus operator so that it puts it in the correct number of buckets. so the first item goes in bucket 0, 2nd in bucket 1, 3rd in bucket 2, 4th in bucket 0, etc...


while keith rousseau is correct, i would argue that the idea is a rather bad way to achieve this. you can achieve it more purely (i.e., without having to mutate a captured variable) via:

var splits =, index) => new { item = item, index = index })
                 .groupby(pair => pair.index % parts, element => element.item)
                 .select(group => group.asenumerable());

Related Query

More Query from same tag