Split List into Sublists with LINQ

Posted by Felipe Lima on Stack Overflow See other posts from Stack Overflow or by Felipe Lima
Published on 2009-01-07T02:43:22Z Indexed on 2010/04/09 10:33 UTC
Read the original article Hit count: 1557

Filed under:
|

Hi all,

I believe this is another easy one for you LINQ masters out there. Is there any way I can separe a List into several separate lists of SomeObject, using the item index as the delimiter of each split?

Let me exemplify: I have a List<SomeObject> and I need a List<List<SomeObject>> or List<SomeObject>[], so that each of these resulting lists will contain a group of 3 items of the original list (sequentially).

eg.: Original List: [a, g, e, w, p, s, q, f, x, y, i, m, c]

Resulting lists: [a, g, e], [w, p, s], [q, f, x], [y, i, m], [c]

I'd also need the resulting lists size to be a parameter of this function.

Is it possible??

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ