-
Notifications
You must be signed in to change notification settings - Fork 0
/
2
40 lines (40 loc) · 1.23 KB
/
2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public class Student : IComparable
{
public double mygrade;
public string mysubject, myID;
public Student() {
public Student(double grade, string subject, string id)
{
mygrade = grade;
mysubject = subject;
myID = id;
}
int IComparable.CompareTo(Object obj)
{
if (obj is Student)
{
Student stu = (Student)obj;
if (this.mygrade > stu.mygrade) return 1;
else if (this.mygrade < stu.mygrade) return -1;
else return 0;
}
throw new ArgumentException("object is not a Student");
}
}
internal class Program
{
static void Main(string[] args)
{
Student[] students = new Student[5];
students[0] = new Student(50.0, "windows程序设计", "001");
students[1] = new Student(90.0, "windows程序设计", "002");
students[2] = new Student(100.0, "windows程序设计", "003");
students[3] = new Student(70.0, "windows程序设计", "004");
students[4] = new Student(80.0, "windows程序设计", "005");
Array.Sort(students);
foreach (Student s in students)
{
Console.WriteLine(s.mygrade + " " + s.mysubject + " " + s.myID);
}
}
}