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