[轉貼] C# 陣列的宣告方式

2012080714:01
出處:http://m955.com/wp/archives/165

            //第1種宣告方式
            string[] arr1 = new string[5];
 
            //第2種宣告方式,不指定陣列大小
            string[] arr2 = new string[]
                            {"王家豪", "鄭惠婷", "蔡昱友", "蔡雅芳", "林嬌岳"};
          
            //第3種宣告方式,直接指定初值,比較方便
            string[] arr3 = { "陳苑星", "陳宏行", "陳麗娟", "趙智和", "白嘉鳳" };
          
            //多維陣列
            string[,] arr4 = { { "王", "趙", "白" }, { "陳", "蔡", "郭" } };
          
            //讀出arr3
            for (int i = 0; i <5; i++)
            {
                Console.Write(arr3[i] + "\n");
            }
          
            //讀出arr4
            for (int j = 0; j <2; j++)
            {
                for (int n = 0; n <3; n++)
                    Console.Write(arr4[j, n] + "\n");
            }
            Console.ReadLine();