Created
May 1, 2012 14:22
-
-
Save andersonimes/2568262 to your computer and use it in GitHub Desktop.
[LINQ]Chunk Operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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