9. C # Basic finishing (Multidimensional arrays)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.