Initializing Array Elements int[] myIntArray = new int[5] { 2, 4, 6, 8, 10 }; // longer syntax int[] myIntArray = { 2, 4, 6, 8, 10 }; // shorter syntax
定义2行3列的int 类型的数组
int [ , ] myRectangularArray = new int[2,3];
The params keyword allows you to pass in a variable number of parameters without necessarily explicitly creating the array.
初始化4行3列的int 类型的数组
const int rows = 4; const int columns = 3; // imply a 4x3 array int[,] rectangularArray = { {0,1,2}, {3,4,5}, {6,7,8}, {9,10,11} }; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { Console.WriteLine("rectangularArray[{0},{1}] = {2}", i, j, rectangularArray[i, j]); } }
时间: 2024-09-29 20:31:15