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