Multidimensional Array 1, two-dimensional array:
Representation method:
Int[y,x],x, Y is the index, Y represents the row, and X represents the column.
Cases:
int New int [23]{{3,2,5},{6,7, 8 }}; // {} can not write
Modification Method:
second[013; indicates that the number in column 1th of row No. 0 is changed to 3
Exercise: bubble sort with a two-dimensional array:
Enter the number of people, enter each person's age, height, name, average age, by height from high to low sort
Console.WriteLine ("Please enter the number of people:"); intn =int. Parse (Console.ReadLine ()); string[,] ren =New stringN3]; //Enter information for each student separately for(inti =0; I < n; i++) {Console.WriteLine ("Please enter your name, age, and height, separated by the ENTER key:"); for(intj =0;j<3; j + +) {ren[i, j]=Console.ReadLine (); } } Doublesum =0; //Calculate total age, print average age for(inti =0; i<n;i++) {sum= Sum +int. Parse (Ren[i,1]); } Console.WriteLine ("The average age is: {0}", Math.floor (sum/N)); Console.WriteLine ("Name Age Height"); //Sort by Height for(inti =0; I < n; i++) { for(intj = i; J < N; J + +) { if(int. Parse (Ren[j,2]) >int. Parse (Ren[i,2])) { string[] Zhong = {ren[j,0],ren[j,1],ren[j,2]}; //Exchange all information to keep your height in alignment with your name and ageRen[j,0] = Ren[i,0]; Ren[j,1] = Ren[i,1]; Ren[j,2] = Ren[i,2]; Ren[i,0] = zhong[0]; Ren[i,1] = zhong[1]; Ren[i,2] = zhong[2]; } } } int[,] ab =New int[0,0]; for(inti =0; I < n; i++) { for(intj =0; J <3; J + +) {Console.Write (Ren[i, J]+" "); } console.write ("\ n"); }* 2, multidimensional array
Notation: Int[z,y,x]:z indicates that there are several two-dimensional arrays, using the same method as the two-dimensional array
9. C # Basic finishing (Multidimensional arrays)