输入三个学生的信息
学号、姓名、分数
从大到小排序
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6
7 namespace 复习CS
8 {
9 class Program
10 {
11 struct Student
12 {
13 public int num;
14 public string Code;
15 public string Name;
16 public decimal Score;
17 }
18
19 static void Main(string[] args)
20 {
21 //1、循环添加学生信息
22 ArrayList list = new ArrayList();
23
24 for (int i = 1; i < 4; i++)
25 {
26 Student s = new Student(); //实例化
27
28 Console.Write("请输入第" + i + "个学生的学号:");
29 s.Code = Console.ReadLine();
30 Console.Write("请输入第" + i + "个学生的姓名:");
31 s.Name = Console.ReadLine();
32 Console.Write("请输入第" + i + "个学生的成绩:");
33 s.Score = Convert.ToDecimal(Console.ReadLine());
34 s.num = i;
35
36 list.Add(s);
37 Console.WriteLine("===============================");
38 }
39
40 Console.WriteLine("-----------------------学生数据展示--------------------------");
41
42 //2、排序
43
44 for (int i = 0; i < list.Count - 1; i++)
45 {
46 for (int j = i + 1; j < list.Count; j++)
47 {
48 Student s1 = (Student)list[i];
49 Student s2 = (Student)list[j];
50
51 if (s1.Score < s2.Score)
52 {
53 Object ob = list[i];
54 list[i] = list[j];
55 list[j] = ob;
56 }
57 }
58 }
59
60 //3、打印
61 foreach (object o in list)
62 {
63 Student ss = (Student)o;
64 Console.WriteLine("第" + ss.num + "个学生的学号:" + ss.Code + ",姓名:" + ss.Name + ",分数:" + ss.Score + "。");
65 }
66
67
68
69 Console.ReadKey();
70 }
71 }
72 }
![](https://images2015.cnblogs.com/blog/943861/201606/943861-20160616214046729-1279367477.png)