static void Main(string[] args)
{
int[,] day = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
print(day);
} private static void print(int[,] arr)
{
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.WriteLine("Element({0},{1})={2}",i,j,arr[i,j]);
}
}
Console.ReadKey();
}
如图,怎么理解?
特别是GetLength(0)的意思等~~~
最后的结果为什么是相加?
http://msdn.microsoft.com/zh-cn/library/system.array.getlength.aspx
GetLength(0)的意思是取得第1维元素的长度4,因为每一维又是数组,所以要继续GetLength(1)【第二维】得到这个元素【数组】的长度,打印。。
那一共就应该执行16次?
但真实的情况是执行了8次,也就是arr.GetLength(1)=2.
还有就是 {2}=arr{i,j} 为何最终输出1,2,3,4~~~ 他们相加了还是怎么了?
arr.GetLength(1):代表没组有多少个数,这里是2个,就为2.最后的arr[i,j]分别代表哪个组里的第几个数。如[2,1],就是值:第3个组,第2个数字:为6.