C#-多維陣列:規則與不規則的型式
規則:
int[, ,] A = { {{2,3}, {52,41}, {37,6}}, {{8,4}, {5,4}, {17,26}}, {{52,30}, {85,24}, {57,6}} }; Console.WriteLine("A[0,1,1] = {0}", A[0, 1, 1]); Console.WriteLine("A[0,1,1] = {0}", A[0, 1, 1]); }
不規則:
int[][][] A = new int[2][][]; A[0] = new int[2][]; A[1] = new int[1][]; A[0][0] = new int[] { 3, 4, 5, 7 }; A[0][1] = new int[] { 2, 4 }; A[1][0] = new int[] { 4, 5, 7 }; Console.WriteLine("A[0][1][0] = {0}", A[0][1][0]); Console.WriteLine("A[0][1][1] = {0}", A[0][1][1]); Console.WriteLine("A[0][1][2] = {0}", A[0][1][2]); //2、4、0、發生執行時期的例外錯誤 Array index out of bound