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)的意思等~~~
最后的结果为什么是相加?

解决方案 »

  1.   

    特别是GetLength(0)的意思是取得第1维元素的长度4,因为每一维又是数组,所以要继续GetLength(1)得到这个元素【数组】的长度,打印,然后就没有然后了
      

  2.   

    Console.WriteLine("Element({0},{1})={2}\n",i,j,arr[i,j]);      
    http://msdn.microsoft.com/zh-cn/library/system.array.getlength.aspx
      

  3.   

    你这是个2维数组,矩形的[,].
    GetLength(0)的意思是取得第1维元素的长度4,因为每一维又是数组,所以要继续GetLength(1)【第二维】得到这个元素【数组】的长度,打印。。
      

  4.   

    楼上的意思是arr.GetLength(0) 为 1357   =4?那arr.GetLength(1) 也是等于4?
    那一共就应该执行16次?
    但真实的情况是执行了8次,也就是arr.GetLength(1)=2.  
    还有就是  {2}=arr{i,j}  为何最终输出1,2,3,4~~~ 他们相加了还是怎么了?
      

  5.   

    OK,感谢,解决了!写出理解方式(就是多维数组):arr.GetLength(0):代表有多少组,这里有4组,就为4.
    arr.GetLength(1):代表没组有多少个数,这里是2个,就为2.最后的arr[i,j]分别代表哪个组里的第几个数。如[2,1],就是值:第3个组,第2个数字:为6.