1. Two-dimensional array
A two-dimensional array is made up of multiple one-dimensional arrays, defined in such a way that:
int [,] array=newint [3,4]{ {1,2,3, 4 }, {3,4,5,6}, {5,6 ,7,8} };
Two-dimensional array of parentheses, the left side of the comma represents the number of one-dimensional array, or control the row, the number after the comma indicates that each one-dimensional array contains several elements, also can be said to control the column.
Exercise: 1. Enter the number of classes, enter each person's English scores, and output
Console.Write ("Please enter the number of classes:"); intA =int. Parse (Console.ReadLine ()); Double[,] score =New DoubleA3]; for(inti =0; i < A; i++) {Console.Write ("Please enter the language score for the {0} individual:", i +1); Score[i,0] =Double. Parse (Console.ReadLine ()); Console.Write ("Please enter the math score for the {0} individual:", i +1); Score[i,1] =Double. Parse (Console.ReadLine ()); Console.Write ("Please enter the English score for the {0} individual:", i +1); Score[i,2] =Double. Parse (Console.ReadLine ()); } for(inti =0; i < A; i++) { for(intj =0; J <3; J + +) {Console.Write (Score[i, J]+"\ t"); } Console.WriteLine (); }
2. Print the word "King"
3. Enter the number of classes, enter the number of each person's English results, the language of the two highest score mathematics two the lowest score of English average
Console.Write ("Please enter the number of classes:"); intA =int. Parse (Console.ReadLine ()); Double[,] score =New DoubleA3]; for(inti =0; i < A; i++) {Console.Write ("Please enter the language score for the {0} individual:", i +1); Score[i,0] =Double. Parse (Console.ReadLine ()); Console.Write ("Please enter the math score for the {0} individual:", i +1); Score[i,1] =Double. Parse (Console.ReadLine ()); Console.Write ("Please enter the English score for the {0} individual:", i +1); Score[i,2] =Double. Parse (Console.ReadLine ()); } for(inti =0; I < A-1; i++) { for(intj = i +1; J < A; J + +) { if(Score[i,0] < Score[j,0]) { DoubleZhong = score[i,0]; Score[i,0] = Score[j,0]; Score[j,0] =Zhong; Zhong= Score[i,1]; Score[i,1] = Score[j,1]; Score[j,1] =Zhong; Zhong= Score[i,2]; Score[i,2] = Score[j,2]; Score[j,2] =Zhong; }}} Console.WriteLine ("two languages highest score is {0}, {1}", score[0,0], score[1,0]); for(inti =0; I < A-1; i++) { for(intj = i +1; J < A; J + +) { if(Score[i,1] > Score[j,1]) { DoubleZhong = score[i,0]; Score[i,0] = Score[j,0]; Score[j,0] =Zhong; Zhong= Score[i,1]; Score[i,1] = Score[j,1]; Score[j,1] =Zhong; Zhong= Score[i,2]; Score[i,2] = Score[j,2]; Score[j,2] =Zhong; }}} Console.WriteLine ("Two math minimum points are {0}, {1}", score[0,1], score[1,1]); Doublesum =0; for(inti =0; i < A; i++) {sum+ = Score[i,2]; } Console.WriteLine ("The average English score is {0}", sum/a);
Another: Split () with .... To split
The segmented content needs to be placed in an array of type string without having to define the length of the array
2. Three-dimensional arrays
How to define:
int[,,] array = new int[3, 2, 2];
Summary: An element is a point
A one-dimensional array is a line
A two-dimensional array is a polygon (table)
A three-dimensional array is a body (stereo)
Two-dimensional arrays & multidimensional arrays