c#笔记(六)——数组(2)

//将一个二维数组的行和列交换,存储到另外一个数组中
            //int[,] a = new int[2, 3] { { 1, 2 ,3},{ 4, 5, 6 } };
           // int[,] b = new int[a.GetLength(1), a.GetLength(0)];
           // for (int i = 0; i < b.GetLength(0); i++)
           // {
           //     for (int j = 0; j < b.GetLength(1); j++)
           //     {
           //         b[i, j] = a[j, i];
           //         Console.Write(b[i,j]+" ");
           //     }
           //     Console.WriteLine();
           //}
//有个3行4列的二维数组,求最大元素以及所在的行和列
            //int[,] a = new int[3, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
            //int max, row, line;
            //max = a[0,0];
            //row = 0;
            //line = 0;
            //for (int i = 0; i < a.GetLength(0); i++)
            //{
            //    for (int j = 0; j < a.GetLength(1); j++)
            //    {
            //        if (max < a[i, j])
            //        {
            //            max = a[i, j];
            //            row = i;
            //            line = j;
            //        }
            //    }
            //}
            //Console.WriteLine("max={0},行号是{1},列号是{2}", max, row+1, line+1);
           赋值一个二维数组
//int[,] a = new int[4, 3];
            //for (int i = 0; i < a.GetLength(0); i++)
            //{
            //    Console.WriteLine("请输入第{0}行赋值的数",i);
            //    for (int j = 0; j < a.GetLength(1); j++)
            //    {
            //        a[i, j] = int.Parse(Console.ReadLine());
            //    }
 
            //}
            //Console.ReadKey();
            ////打印数组
            //Console.WriteLine("打印赋值的数组");
            //for (int i = 0; i < a.GetLength(0); i++)
            //{
            //    for (int j = 0; j < a.GetLength(1); j++)
            //    {
            //        Console.Write(a[i, j] + " ");
            //    }
            //    Console.WriteLine();
            //}
 
            //Console.WriteLine("第一行元素");
            //for (int i = 0; i < a.GetLength(1); i++)
            //{
            //    Console.Write(a[0, i] + " ");
            //}
            //Console.WriteLine("和");
            //int sum = 0;
            //for (int i = 0; i < a.GetLength(1); i++)
            //{
            //    sum += a[1, i];
            //}
            //Console.WriteLine("sum=" + sum);
原文地址:https://www.cnblogs.com/ningyongbin/p/5922151.html