C # Example: Enter student number, name, score, and then sort by score. This problem is done with a set and a struct, which is different from the previous question. It's important to master basic knowledge

Source: Internet
Author: User
Tags readline

 classProgram {structStudent { Public stringname;  Public intCode;  Public intAge ;  Public DoubleFenshu; }        Static voidMain (string[] args) {ArrayList Al=NewArrayList ();//to define a new collectionConsole.Write ("Please enter the number of people:"); intRenshu =Convert.ToInt32 (Console.            ReadLine ());  for(inti =0; I <renshu; i++) {Student R=Newstudent (); Console.Write ("Please enter section"+ (i+1)+"name of individual:"); R.name=Console.ReadLine (); Console.Write ("Please enter section"+ (i +1) +"Individual study number:"); R.code=Convert.ToInt32 (Console.                ReadLine ()); Console.Write ("Please enter section"+ (i +1) +"Age of individual:"); R.age=Convert.ToInt32 (Console.                ReadLine ()); Console.Write ("Please enter section"+ (i +1) +"Personal Score:"); R.fenshu=convert.todouble (Console.                ReadLine ()); Al.                                            ADD (R); //Put the R data in the Al collection.            }                ;  for(inti =0; i < Renshu; i++)                {                     for(intj = i; J < renshu-1; J + +)                                            if(((student) al[i]) .fenshu< ((student) al[j+1]). Fenshu)//to compare the scores from the collection of student structures{student Zhong; Zhong=(student) al[i]; Al[i]= Al[j +1]; Al[j+1] =Zhong; }} Console. WriteLine ("order of students after sorting:");  for(inti =0; i < Renshu; i++) {Console.WriteLine ("name \ t"+ ((student) al[i]). Name +"School number \ t"+ ((student) al[i]). Code +"age \ t"+((student) al[i]). Age+"score \ t"+((student) al[i]). Fenshu);                } console.readline (); }            }        }

C # Example: Enter student number, name, score, and then sort by score. This problem is done with a set and a struct, which is different from the previous question. It's important to master basic knowledge

Related Article

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.