Here i splitted array of ints into 2 arrays of 4 and the left elements:
var limit = 4;
int[] array = new int[] { 1, 2, 3, 4, 5, 6 };
int[][] res = array.Select((value, index) => new { index = index, value = value })
.GroupBy(i => i.index < limit)
.Select(g => g.Select(o => o.value).ToArray())
.ToArray();
UPD: remake with an extension:
class Program
{
static void Main(string[] args)
{
int[] array = new int[] { 1, 2, 3, 4, 5, 6 };
int[][] res = array.split(4);
}
}
static class MyExtension
{
public static int[][] split(this IEnumerable<int> array, int limit)
{
return array.Select((value, index) => new { index = index, value = value })
.GroupBy(i => i.index < limit)
.Select(g => g.Select(o => o.value).ToArray())
.ToArray();
}
}