Skip to content

Instantly share code, notes, and snippets.

@stonetip
Created January 30, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stonetip/ad17d5d2b52e29d3e2a869b95541737c to your computer and use it in GitHub Desktop.
Save stonetip/ad17d5d2b52e29d3e2a869b95541737c to your computer and use it in GitHub Desktop.
Sweet little C# method for subdividing a list - based on answers from http://stackoverflow.com/questions/11463734/split-a-list-into-smaller-lists-of-n-size
public static List<List<T>> SubdivideList<T>(List<T> inputList, int divisionSize = 2)
{
var subdivisionsList = new List<List<T>>();
for (var i = 0; i < inputList.Count; i += divisionSize)
{
subdivisionsList.Add(inputList.GetRange(i, Math.Min(divisionSize, inputList.Count - i)));
}
return subdivisionsList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment