Skip to content

Instantly share code, notes, and snippets.

@Ondrya
Forked from relyky/SplitList.cs
Created May 18, 2020 09:33
Show Gist options
  • Save Ondrya/ac54a4fbb24a9e59d9f4e9b779663fe7 to your computer and use it in GitHub Desktop.
Save Ondrya/ac54a4fbb24a9e59d9f4e9b779663fe7 to your computer and use it in GitHub Desktop.
c#, Split List, Split a List into smaller lists of N size
///
/// Split a List into smaller lists of N size
/// ref → http://stackoverflow.com/questions/11463734/split-a-list-into-smaller-lists-of-n-size
///
public static IEnumerable<List<T>> SplitList<T>(List<T> bigList, int nSize = 3)
{
for (int i = 0; i < bigList.Count; i += nSize)
{
yield return bigList.GetRange(i, Math.Min(nSize, bigList.Count - i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment