Chapter 4. 数组

       // 一维数组
            // 定义方式:int [ ] 变量名 = new int [ n ];
            // 初始化:int [ ] myArray = new int [ ] {1,2,3,4,5};
            string [] weekdays = new string [] 
                {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
            String s=weekdays[2];
            Console.WriteLine(s);
            Console.ReadLine();

            //二维数组
            //定义方式:int [,] myArray = new int [几个一维数组 , 数组中元素的个数];
            int [,] myArray = new int [4,2];
            int [,] myArray1 = new int [4,2]{{1,2},{3,4},{5,6},{7,8}};
            Console.WriteLine(myArray1[0,1]);
            Console.ReadLine();

            //多维数组
            int [,,] myArray2 = new int [2,4,2]
            {
                {{1,2},{3,4},{5,6},{7,8}},
                {{9,10},{11,12},{13,14},{15,16}}
            };
            Console.WriteLine(myArray2[0,0,1]);
            Console.ReadLine();

posted @ 2016-05-10 23:14  庚xiao午  阅读(104)  评论(0编辑  收藏  举报