Skip to content

Instantly share code, notes, and snippets.

@andersonimes
Created May 1, 2012 14:22
Show Gist options
  • Save andersonimes/2568262 to your computer and use it in GitHub Desktop.
Save andersonimes/2568262 to your computer and use it in GitHub Desktop.
[LINQ]Chunk Operator
/// <summary>
/// Break a list of items into chunks of a specific size
/// </summary>
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunksize)
{
while (source.Any())
{
yield return source.Take(chunksize);
source = source.Skip(chunksize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment