C # review:
Problem:
Add 5 Student information to the collection,
Each student has: study number, name, score, 3 content,
The students ' scores are arranged from high to low and printed out after the completion of the addition.
1 Define a set of variables in other classes 2 3 4 class student 5 { 6 public string code; 7 public string name; 8 public decimal score; 9 }
1ArrayList ary =NewArrayList ();2 for(inti =1; I <6; i++)3 {4Student S =Newstudent ();5Console.Write ("Please enter section"+ i +"Student's School number:");6S.code =console.readline ();7Console.Write ("Please enter section"+ i +"the name of a student:");8S.name =console.readline ();9Console.Write ("Please enter section"+ i +"A student's achievement:");TenS.score =decimal. Parse (Console.ReadLine ()); One ary. ADD (s); AConsole.WriteLine ("-----------------------------------------------------"); - Console.Write (s.score); - } the for(inti =0; i < ary. Count; i++) - { - for(intL = i +1; L < ary. Count; l++) - { +Student S1 =(student) ary[i]; -Student S2 =(student) ary[l]; + if(S1.score <S2.score) A { at ObjectZhong =Ary[i]; -Ary[i] =Ary[l]; -ARY[L] =Zhong; - } - } - } in foreach(ObjectOinchary) - { toStudent oo =(student) O; +Console.WriteLine (oo.code+"\ t"+oo.name+"\ t"+oo.score); -}
C # Review Questions