Is there any way I can separate a List
into several separate lists of SomeObject
, using the item index as the delimiter of each s
This question is a bit old, but I just wrote this, and I think it's a little more elegant than the other proposed solutions:
///
/// Break a list of items into chunks of a specific size
///
public static IEnumerable> Chunk(this IEnumerable source, int chunksize)
{
while (source.Any())
{
yield return source.Take(chunksize);
source = source.Skip(chunksize);
}
}