/******************************************************************** @date 2014-10-22 @author Tiger @brief 语法 @details C#二维数组 ********************************************************************/ using System; class Demo { static void Main() { int[,] arr = new int[4, 4] { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12},{13, 14, 15, 16}}; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { Console.Write(arr[i, j] + " "); } Console.WriteLine(); } for (int i = 0; i < 4; ++i) { for (int j = i + 1; j < 4; ++j) { int nTemp = arr[i, j]; arr[i, j] = arr[j, i]; arr[j, i] = nTemp; } } for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { Console.Write(arr[i, j] + " "); } Console.WriteLine(); } Console.ReadLine(); } }
时间: 2024-11-10 08:57:34