Foreach with takeN elements instead of 1

Say I have 23 elements in a list. How can I do foreach taking 5 elements each time and 3 elements the last time? Is there anything like "takeN" method which I can use with foreach or something?

// myList is a list 23 elements
foreach (var x in myList) {
  // x is a list with 5 elements
}
Jon Skeet
people
quotationmark

There's nothing in the framework, but you can use MoreLINQ's Batch method:

foreach (var sublist in myList.Batch(5))
{
    // sublist has up to 5 elements
}

(On the final iteration, it will have just 3 elements.)

people

See more on this question at Stackoverflow