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
It's an old solution but I had a different approach. I use Skip
to move to desired offset and Take
to extract desired number of elements:
public static IEnumerable> Chunk(this IEnumerable source,
int chunkSize)
{
if (chunkSize <= 0)
throw new ArgumentOutOfRangeException($"{nameof(chunkSize)} should be > 0");
var nbChunks = (int)Math.Ceiling((double)source.Count()/chunkSize);
return Enumerable.Range(0, nbChunks)
.Select(chunkNb => source.Skip(chunkNb*chunkSize)
.Take(chunkSize));
}