2018年6月8日 星期五

陣列宣告方式

出處: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();

沒有留言:

張貼留言

WPF聊天室应用(ASP.NET Core SignalR)

  WPF聊天室应用(ASP.NET Core SignalR) https://www.bilibili.com/video/BV1Q741187Si?p=2 https://www.bilibili.com/video/BV1UV411e75T?from=search&...