if i need to split array in to specific length as example let say i have array with 16 elements and i wanna split this in to 3 arrays and each array include 5 elements when it comes to last array should take rest of them so output should be something like this
- array 1 with 5 elements
- array 2 with 5 elements
- array 3 with 6 elements
i really like this answer but it cannot split in to predefined length
public static IEnumerable<List<int>> SplitWhenNotIncreasing(List<int> numbers)
{
for (int i = 1, start = 0; i <= numbers.Count; ++i)
{
if (i != numbers.Count && numbers[i] > numbers[i - 1])
continue;
yield return numbers.GetRange(start, i - start);
start = i;
}
}