Below function helps to split existing list into multiple, set nSize to any number and it will create lists of same size.
This can be very useful for parallel LINQ.
- public static List<List<Class Name>> splitList(List<Class Name> locations, int nSize = 20000)
- {
-
- var list = new List<List<Class Name>>();
-
- for (int i = 0; i < locations.Count; i += nSize)
-
- {
-
- list.Add(locations.GetRange(i, Math.Min(nSize, locations.Count - i)));
-
- }
-
- return list;
-
- }