How to split List2 to 3 lists,
first list 4 items
second list 4 items
third list 2 items
public static class ListExtensions
{
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize)
{
return source
.Select((x, i) => new { Index = i, Value = x })
.GroupBy(x => x.Index / chunkSize)
.Select(x => x.Select(v => v.Value).ToList())
.ToList();
}
}
double[][] x;
x = new double[10][];
for (int ii = 0; ii < 10; ii++)
{
x[ii] = new double[4];
for (int jj = 0; jj < 4; ++jj)
x[ii][jj] = 0.45;
}
// Convert x matrix to list
List<double[][]> List2= new List<double[][]>();
List2.Add(x);
List<double[][]> List1 = new List<double[][]>();
List1 = ListExtensions.ChunkBy(List2, 3)[0]; // must be List of double[][]
Console.Write(List1.Count ); // it should be 3
Console.ReadLine();
List1 should includes 3 lists of double[][], but i have got one list,
List1.Count : 1
List1 shoulde be like this:
List1[0] = x[0], x[1], x[2], x[3]
List1[1] = x[4], x[5], x[6], x[7]
List2[2] = x[8], x[9]