C # example: Enter student's number, name, score, then sort by score and then output the final result. Key learning to define the expression of an array with struct-body

Source: Internet
Author: User

 classProgram {structStudent//define a struct body        {             Public intCode;  Public stringname;  Public intFenshu; }        Static voidMain (string[] args) {Console.Write ("Please enter the number of people:"); intRenshu =Convert.ToInt32 (Console.            ReadLine ()); Student[] R=NewStudent[renshu];//defines an array of student types for a struct             for(inti =0; i < Renshu; i++) {Console.Write ("The sentiment enters the first", (n+1)+"Individual study number:"); R[i].code= Convert.ToInt32 (Console. ReadLine ());//Notice how an array with a structured body literal is expressedConsole.Write ("Please enter section", (n+1)+"name of individual:"); R[i].name=Console.                ReadLine (); Console.Write ("Please enter section", (n+1)+"Personal Score:"); R[i].fenshu=Convert.ToInt32 (Console.            ReadLine ()); }             for(inti =0; i < Renshu; i++)            {                 for(intj = i; J < Renshu-1; J + +)                {                    if(R[i].fenshu <r[j+i].fenshu)//to sort by fractions{Student Temp=R[i]; R[i]= R[j +1]; R[j+1] =temp; }}} Console.WriteLine ("the order after sorting is:");  for(inti =0; I <renshu; i++)//Output Final Result{Console.WriteLine ("School Number"+r[i].code +"\ t Name"+r[i].name +"\ t Fraction"+R [I].fenshu];        } console.readline (); }    }}

C # example: Enter student's number, name, score, then sort by score and then output the final result. Key learning defines the expression of an array using a struct

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.