C#拆分双[] []的LIST

时间:2017-12-15 09:26:47

标签: c# list

如何将List2拆分为3个列表,

首先列出4个项目

第二个清单4项

第三个清单2项

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应该包含3个double [] []列表,但我有一个列表,

List1.Count : 1

List1应该是这样的:

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]

1 个答案:

答案 0 :(得分:1)

我希望这是你需要的功能:

edittext.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);