C#复习题

C#复习:
题:
添加5个学生的信息到集合中,
每个学生都有:学号,姓名,成绩,3个内容,
添加完毕后将学生的分数从高到低排列并打印出来

1 在其他类中定义一组变量
2 
3 
4 class student
5     {
6         public string code;
7         public string name;
8         public decimal score;
9     }
 1  ArrayList ary = new ArrayList();
 2             for (int i = 1; i < 6; i++)
 3             {
 4                 student s = new student();
 5                 Console.Write("请输入第" + i + "个学生的学号:");
 6                 s.code = Console.ReadLine();
 7                 Console.Write("请输入第" + i + "个学生的名字:");
 8                 s.name = Console.ReadLine();
 9                 Console.Write("请输入第" + i + "个学生的成绩:");
10                 s.score = decimal.Parse(Console.ReadLine());
11                 ary.Add(s);
12                 Console.WriteLine("-----------------------------------------------------");
13                 Console.Write(s.score);
14             }
15             for (int i = 0; i < ary.Count; i++)
16             {
17                 for (int l = i + 1; l < ary.Count; l++)
18                 {
19                     student s1 = (student)ary[i];
20                     student s2 = (student)ary[l];
21                     if (s1.score < s2.score)
22                     {
23                         object zhong = ary[i];
24                         ary[i] = ary[l];
25                         ary[l] = zhong;
26                     }
27                 }
28             }
29             foreach(object o in ary)
30             {
31                 student oo = (student)o;
32                 Console.WriteLine(oo.code+"	"+oo.name+"	"+oo.score);
33             }
原文地址:https://www.cnblogs.com/mazhijie/p/5592103.html