How to convert List> to an array of arrays

后端 未结 4 721
刺人心
刺人心 2020-12-08 19:40

What is the best way to convert a list into an array of type int[][]?

List> lst = new List>();
         


        
4条回答
  •  青春惊慌失措
    2020-12-08 20:07

    There's no library function to do this.

    You'll need to do this with loops.

    int[][] newlist = new int[lst.Size][];
    for (int i = 0; i < lst.Size; i++)
    {
        List sublist = lst.ElementAt(i);
        newlist[i] = new int[sublis.Size];
        for (int j = 0; j < sublist.Size; j++)
        {
            newlist[i][j] = sublist.ElementAt(j);
        }
    }
    

    There you go!

提交回复
热议问题