Is there a nice way to split a collection into n
parts with LINQ?
Not necessarily evenly of course.
That is, I want to divide the collection into sub-collections, which each contains a subset of the elements, where the last collection can be ragged.
This is my code, nice and short.
If order in these parts is not very important you can try this:
However these can't be cast to IEnumerable<IEnumerable<int>> by some reason...
This is my way, listing items and breaking row by columns
Great Answers, for my scenario i tested the accepted answer , and it seems it does not keep order. there is also great answer by Nawfal that keeps order. But in my scenario i wanted to split the remainder in a normalized way, all answers i saw spread the remainder or at the beginning or at the end.
My answer also takes the remainder spreading in more normalized way.
Here is a little tweak for the number of items instead of the number of parts: