C# 數組(Array)
數組是一個存儲相同類型元素的固定大小的順序集合數組
數組html
數組是一個存儲相同類型元素的固定大小的順序集合。web
static void Main(string[] args) { //數組A int[,] a = new int[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, }; //數組B int[,] b = new int[3, 3] { { 4, 5, 6 }, { 7, 8, 9 }, { 1, 2, 3 }, }; //輸出數組A Console.WriteLine("輸出數組A"); for (int i = 0; i < a.GetLength(0); i++) { for (int j = 0; j < a.GetLength(1); j++) { Console.Write(a[i, j]+"\t"); } Console.WriteLine(); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); //輸出數組B Console.WriteLine("輸出數組B"); for (int i = 0; i < b.GetLength(0); i++) { for (int j = 0; j < b.GetLength(1); j++) { Console.Write(a[i, j]+"\t"); } Console.WriteLine(); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); //數組C Console.WriteLine("輸出數組C"); int[,] c = new int[3, 3]; for (int i = 0; i < c.GetLength(0); i++) { for (int j = 0; j < c.GetLength(1); j++) { Console.Write(a[i, j] + b[i, j]+"\t"); } Console.WriteLine(); Console.WriteLine(); } Console.ReadKey(); }
數組A+數組B=數組C正則表達式
而後Foreach循環遍歷控制檯輸出結果express
數組是一個存儲相同類型元素的固定大小的順序集合數組