Two-dimensional arrays:
define a two-dimensional array int[,] MyArray = new Int[several one-dimensional arrays, the number of arrays];
An array can have more than one Dimension. For example, The following declaration creates a two-dimensional array of four rows and two columns (which can be understood as 4 1-dimensional arrays, with 2 elements in the array):
int[,] MyArray = new int[4,2];
int[,] MyArray = new int[4,2] {{}, {3,4}, {5,6}, {7,8}};
The value is
Int i=myarray[0,0]
the output Result i is: 1
Int i=myarray[0,1]
the output Result i is: 2
Multidimensional Arrays:
An array can have more than one Dimension. For example:
int[,,] MyArray = new int[2,4,2] {{1,2},{3,4},{5,6},{7,8}}, {{9,10},{11,12},{13,14},{15,16}};
An element is a point one-dimensional array is a line of two-dimensional arrays a polygon (table) three-dimensional array is a teaching building (stereoscopic)
Split ()
* * * Split the content needs to be placed in a string type of array, do not need to define the length of the array
Console.Write (" Please enter name-age-work unit:"); // "zhang San -33-han enterprise" string s = console.readline (); string [] array = s.split ('-'); foreach (string in array) { Console.WriteLine (aa);}
Above is an array of a problem, the previous done, this time with an array!!
Enter the number of classes, enter the number of each Person's language scores for the Chinese two highest score, mathematics two minimum points, English average score
Console.Write ("Please enter the number of Classes:"); intA =int. Parse (console.readline ()); Double[,] s =New DoubleA3]; for(inti =0; I < a; i++) {console.write ("Please enter the language score for the {0} Individual:", (i +1)); s[i,0] =Double. Parse (console.readline ()); Console.Write ("Please enter the math score for the {0} Individual:", (i +1)); s[i,1] =Double. Parse (console.readline ()); Console.Write ("Please enter the English score for the {0} Individual:", (i +1)); s[i,2] =Double. Parse (console.readline ()); } for(inti =0; I < a; i++) { for(intj =0; J <3; J + +) {console.write (s[i, j]+"\ t"); } Console.WriteLine (); } for(inti =0; I < a-1; i++) { for(intj = i +1; J < a; J + +) { if(s[i,0] < s[j,0]) { Doublez = s[i,0]; s[i,0] = s[j,0]; s[j,0] =z; DoubleZ1 = s[i,1]; s[i,1] = s[j,1]; s[j,1] =z1; Doublez2 = s[i,2]; s[i,2] = s[j,2]; s[j,2] =z1; }}} Console.WriteLine ("the highest language is divided Into:"+ s[0,0] +","+ s[1,0]); for(inti =0; I < a-1; i++) { for(intj = i +1; J < a; J + +) { if(s[i,1] > s[j,1]) { Doublez = s[i,0]; s[i,0] = s[j,0]; s[j,0] =z; DoubleZ1 = s[i,1]; s[i,1] = s[j,1]; s[j,1] =z1; Doublez2 = s[i,2]; s[i,2] = s[j,2]; s[j,2] =z1; }}} Console.WriteLine ("the Lowest mathematics is divided into:"+ s[0,1] +","+ s[1,1]); Doublesum =0; for(inti =0; I < a; i++) {sum+ = s[i,2]; } Console.WriteLine ("the average English is divided into:"+ sum/a); Console.ReadLine ();
View Code
Note that in the bubbling cycle, as you want to get the fractional interchange, you also swap the other items of the same array, or else the results will be affected.
Find replacement issues
Console.Write ("Spring sleep does not feel xiao, everywhere smell Bird. The night comes the wind and rain, the flowers fall to know how Much. \ n"); Console.Write ("Please enter the text you want to replace:"); stringA =Console.ReadLine (); Console.Write ("Please enter the text you want to replace With:"); stringb =Console.ReadLine (); string[] s =New string[ -] {"Spring","Sleep","No","Sleep","Xiao",",","Place","Place","Smell","Cry","Bird",". ","Night","come to","Wind","Rain","Sound",",","Flowers","Fall","know","more","less",". " }; for(inti =0; I < -; i++) { if(s[i] = =A) {s[i]=b; }} Console.Write ("Replace succeeded, replaced By:"); foreach(stringAainchS) {console.write (aa); } console.readline ();
Method One
string " Spring sleep does not feel xiao, everywhere smell Bird. The night comes the wind and rain, the flowers fall to know how Much. "; Console.Write (" Please enter the word to be replaced:") ; string b = console.readline (); Console.Write (" Please enter the text to be replaced With:"); string c = console.readline (); Console.WriteLine (a.replace (b, c)); Console.ReadLine ();
Method Two
Two-dimensional arrays, multidimensional arrays