protected void Page_Load(object sender, EventArgs e) { /******************************* * 交错数组的使用:(数组的数组) * 参考地址:http://msdn.microsoft.com/zh-cn/library/2s05feca(VS.80).aspx * ***************************/ //例子1: string[][] array = new string[4][] { new string[] {"0","id0","其它0","4","5"}, new string[] {"1","id1","其它1"}, new string[] {"2","id2","其它2"}, new string[] {"3","id3","其它3"} }; Response.Write("交错数组的长度:" + array.Length + "<br/>"); for (int i = 0; i < array.Length; i++) { Response.Write("列表"+(i+1)+":" ); for (int j = 0; j < array[i].Length; j++) { Response.Write(array[i][j]+" "); } Response.Write("<br/>"); } /************************************* * 结果: * 交错数组的长度:4 * 列表1:0 id0 其它0 4 5 * 列表2:1 id1 其它1 * 列表3:2 id2 其它2 * 列表4:3 id3 其它3 * ************************************/ Response.Write("<br/>"); //例子2 int[][,] jaggedArray4 = new int[3][,] { new int[,] { {1,3}, {5,7} }, new int[,] { {0,2}, {4,6}, {8,10} }, new int[,] { {11,22}, {99,88}, {0,9} } }; Response.Write("交错数组的长度:" + jaggedArray4.Length + "<br/>"); for (int i = 0; i < jaggedArray4.Length; i++) { Response.Write("列表" + (i + 1) + ":"); for (int j = 0; j < jaggedArray4[i].Length/2; j++) { Response.Write("["+jaggedArray4[i][j,0] +","+jaggedArray4[i][j,1]+ "] "); } Response.Write("<br/>"); } /************************************************* * 结果: * 交错数组的长度:3 * 列表1:[1,3] [5,7] * 列表2:[0,2] [4,6] [8,10] * 列表3:[11,22] [99,88] [0,9] * **********************************************/ Response.Write("<br/>"); /********************* * * 三维数组的使用 * * *******************/ /*例子1*/ int[, ,] Array3D = new int[,,] { { { 1, 2, 3 } }, { { 4, 5, 6 } }, { { 7, 8, 9 } }, { { 10, 11, 12 } } }; Response.Write("数组长度:"+Array3D.Length+"<br/>"); for (int i = 0; i < Array3D.Length / 3; i++) { Response.Write("第"+(i+1)+"行:"+Array3D[i, 0, 0] +" "+ Array3D[i, 0, 1] +" "+ Array3D[i, 0, 2]); Response.Write("<br/>"); } //也可定义为: int[, ,] Array3Dtmp = new int[4, 1, 3] { { { 1, 2, 3 } }, { { 4, 5, 6 } }, { { 7, 8, 9 } }, { { 10, 11, 12 } } }; /*************************************** * 结果: * 数组长度:12 * 第1行:1 2 3 * 第2行:4 5 6 * 第3行:7 8 9 * 第4行:10 11 12 * ***********************************/ Response.Write("<br/>"); /*例子2*/ int[, ,] Array3D2 = new int[2,2,2] { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } }; /*例子3*/ int[, ,] xyz = new int[2, 3, 4] { {{1,2,3,4}, {5,6,7,8},{9,10,11,12}}, {{13,14,15,16}, {17,18,19,20},{21,22,23,24}} }; Response.Write("三维数组的长度(2*3*4):"+xyz.Length+"<br/>"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 4; k++) { Response.Write(xyz[i,j,k]+" "); } } } /****************************************************************** * 结果: * 三维数组的长度(2*3*4):24 * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 * ***************************************************************/ Response.Write("<br/>"); }