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直接遍历
            }
        }
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM