Reid beat me, but here my method is anyway:
public int[][] Split(int[] source, int size) { int fullArrayCount = source.Length / size; int totalArrayCount = fullArrayCount; int remainder = source.Length - (fullArrayCount * size); if (remainder > 0) { totalArrayCount++; } int[][] output = new int[totalArrayCount][]; for (int i = 0; i < fullArrayCount; i++) { output[i] = new int[size]; Array.Copy(source, i * size, output[i], 0, size); } if (totalArrayCount != fullArrayCount) { output[fullArrayCount] = new int[remainder]; Array.Copy(source, fullArrayCount * size, output[fullArrayCount], 0, remainder); } return output; }
source share