数组

数组是一个存储相同类型元素的固定大小的顺序集合。

 static void Main(string[] args)
        {
            //数组A
            int[,] a = new int[3, 3] 
            { 
                { 1, 2, 3 }, 
                { 4, 5, 6 }, 
                { 7, 8, 9 },
            };
            //数组B
            int[,] b = new int[3, 3]
            { 
                { 4, 5, 6 },
                { 7, 8, 9 }, 
                { 1, 2, 3 },
            };
            //输出数组A
            Console.WriteLine("输出数组A");
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    Console.Write(a[i, j]+"\t");
                }
                Console.WriteLine();
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            //输出数组B
            Console.WriteLine("输出数组B");
            for (int i = 0; i < b.GetLength(0); i++)
            {
                for (int j = 0; j < b.GetLength(1); j++)
                {
                    Console.Write(a[i, j]+"\t");
                }
                Console.WriteLine();
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            //数组C
            Console.WriteLine("输出数组C");
            int[,] c = new int[3, 3];
            for (int i = 0; i < c.GetLength(0); i++)
            {
                for (int j = 0; j < c.GetLength(1); j++)
                {
                    Console.Write(a[i, j] + b[i, j]+"\t");
                }
                Console.WriteLine();
                Console.WriteLine();
            }
            Console.ReadKey();
        }

数组A+数组B=数组C

然后Foreach循环遍历控制台输出结果

数组是一个存储相同类型元素的固定大小的顺序集合

相关文章:

  • 2021-10-26
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2021-11-11
  • 2021-09-05
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案