using System; using System.Collections.Generic; using System.Text; namespace System.Collections.Generic { /// /// A collection of extension methods. /// public static class ListExtensions { /// /// Splits a list into sub lists. /// /// The original list. /// The amount of sub lists to create. /// A list size N of sub lists. public static List> Split(this List list, int n) { List> value = new List>(); int subSize = list.Count / n; int totalCount = 0; for (int i = 0; i < n; i++) { List currentList = new List(); for (int j = 0; j < subSize && totalCount < list.Count; j++) { currentList.Add(list[totalCount]); totalCount++; } value.Add(currentList); } return value; } } }