One-dimensional array "Same data type"//First definition mode//int[] Shuzu = new INT[5]; for (int i = 0; i < 5; i++)//{//shuzu[i] = i + 1; }////index starting from 0///assignment////shuzu[0] = 1; SHUZU[1] = 2; SHUZU[2] = 3; SHUZU[3] = 4; SHUZU[4] = 5; SHUZU[5] = 6; SHUZU[6] = 7; Console.WriteLine (Shuzu[4]); The second way of defining//int[] Shuzu = new int[] {1,2,3,4,5}; Console.WriteLine (Shuzu[2]); Enter the age of 10 people from the console into the array,//sum the ages of 10 people//int [] age=new int [10]; int sum = 0; for (int i = 0; i < i++)//{//Console.Write ("Please enter" + (i+1) + "personal Age:"); Age[i] = Int. Parse (Console.ReadLine ()); Sum + = Age[i]; }//console.writeline (sum); Enter the name of the person into the array, output the names of the 5th persons//console.write ("Please enter a few people:"); int a = Int. Parse (Console.ReadLine ()); string [] name =new string [a]; for (int i = 0; i < a;i++)//{//Console.Write ("Please enter" + (i + 1) + "personal name:"); Name[i] = Console.ReadLine (); }//console.writeline (Name[4]); Enter the number of classes, according to the number of people,//input results, the average//console.write ("Please enter the number of classes:"); int a = Int. Parse (Console.ReadLine ()); Double [] fen = new double [A]; Double sum = 0; for (int i = 0; i < a;i++)//{//Console.Write ("Please enter the section" + (i+1) + "Personal score:"); Fen[i] = double. Parse (Console.ReadLine ()); Sum + = Fen[i]; }//console.writeline ("Class average divided into:" +sum/a); Two-dimensional array//int[,] Shuzu = new int[3, 4]; int[,] Shuzu = new int[,] {//{1, 2,3,4},//{5,6,7,8},//{6,7,8,9}//}; string[,] Shuzu = new string[,] {//{"", "", "", "", "", "" ""},//{"", "", "", "" " ,//{"," "," "," "," "," "," "},//{", "", "", "", "", "", "", "", "" "", "" "" "" "" "" "" " , "", "", ""},//{"", "", "", "", "", "" "," "," "", "", "" "," "", "", "" "," "," "", "" "," "", "" "" ""}; for (int i = 0; i < 7; i++)//{//for (int j = 0; J < 7; J + +)// {//Console.Write (Shuzu[i, j]); }//Console.WriteLine (); }//Input class number, will each person's//language, Mathematics, English score input two-dimensional array//console.write ("Please enter class Number:"); int a = Int. Parse (Console.ReadLine ()); Double [,] Shuzu = new double [a,3]; for (int i = 0; i < A; i++)//{//for (int j = 0; j < 3;)//{//if (j = = 0)//{//Console.Write ("Please enter section" + (i+1) + "Personal language score:"); }//if (j = = 1)//{//Console.Write ("Please enter" + (i + 1 ) + "Personal math score:"); }//if (j = = 2)//{//Console.Write ("Please enter" + (i + 1 ) + "Personal English Score:"); }//Shuzu[i, j] = Double. Parse (Console.ReadLine ()); }//}//Console.ReadLine (); Three-dimensional array//int[,,] Shuzu = new int[3, 2, 4]; //{ // { // {,,,}, // {,,,} // }, // { // {,,,}, // {,,,} // }, // { // {,,,}, // {,,,} // } //};
The array is divided into one-dimensional arrays, two-dimensional arrays, multiple arrays