/ Published in: C#

author SomeMiscGuy@StackOverflow
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static List<T>[] Partition<T>(List<T> list, int totalPartitions) { if (list == null) if (totalPartitions < 1) int maxSize = (int)Math.Ceiling(list.Count / (double)totalPartitions); int k = 0; for (int i = 0; i < partitions.Length; i++) { for (int j = k; j < k + maxSize; j++) { if (j >= list.Count) break; partitions[i].Add(list[j]); } k += maxSize; } return partitions; }
Comments
