2013-10-09 94 views
1

下面列出的代碼是爲了幫助我找到C#中二維數組的行和列大小,但是在訪問列長度時結束了IndexOutOfRangeException( GetLength進行(1))。我查了類似s.o q-a's,但無法確定列大小。二維數組的行列大小

List<List<int>> intLists = new List<List<int>>(); 
    for (int i = 0; i < 2; i++) 
    { 
    List<int> tempList = new List<int>(); 
    for (int j = 0; j < 5; j++) 
     tempList.Add(j + 5+i); 
    intLists.Add(tempList); 
    } 

    int[][] intArray = intLists.Select(Enumerable.ToArray).ToArray(); 

    Console.WriteLine("Dimension 0 Length = " + intArray[0].Length); 
    Console.WriteLine("Dimension 1 Length = " + intArray[1].Length); 
    Console.WriteLine("Dimension 0 Length = " + intArray.GetLength(0)); 
    //Console.WriteLine("Dimension 1 Length = " + intArray.GetLength(1)); 

回答