C#数组2(多维数组)

 

 

using System;

namespace ConsoleApp3
{
    struct WuGong
    {
        public string Name;
        public int Attack;
    }
    class Program
    {
        static void Main(string[] args)
        {
            WuGong[] wg = new WuGong[3];
            wg[0].Name = "辟邪剑法";
            wg[0].Attack = 500;
            wg[1].Name = "降龙十八掌";
            wg[1].Attack = 600;
            wg[2].Name = "暗然消魂掌";
            wg[2].Attack = 400;
            Console.WriteLine(wg[1].Attack);

            int[,] a = { {1,2,3 },{4,5,6 },{7,8,9 } };
           // 1   2   3
           // 4   5   6
           // 7   8   9
            Console.WriteLine(a[0,2]);//3  数组是从0开始计数
            for (int i = 0; i < a.GetLength(0); i++)//取行的长度
            {
                for (int i1 = 0; i1 < a.GetLength(1); i1++)//取列的长度
                {
                    Console.WriteLine(a[i,i1]);
                }
            }
            foreach (var item in a)
            {
                Console.WriteLine(item);//使用foreach直接遍历
            }
        }
    }
}

 

相关文章:

  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-30
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案