Created
July 2, 2023 07:22
-
-
Save IJsWorkshop/213466e5850d75cc0cbdd0c066f511a8 to your computer and use it in GitHub Desktop.
Split a List<T> into a List<List<T>> of nth size
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
public static List<List<T>> ChunkInto<T>(this IList<T> source, int chunkSize) | |
{ | |
return source | |
.Select((x, i) => new { Index = i, Value = x }) | |
.GroupBy(x => x.Index / chunkSize) | |
.Select(x => x.Select(v => v.Value).ToList()) | |
.ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handy function to split/chunk a large List into small nth size Lists - List<List>