class Program
{
static void Main(string[] args)
{
List<Student> array = new List<Student>();
Student st = new Student("aaa", 23, 88);
array.Add(st);
st = new Student("bbb", 24, 90);
array.Add(st);
st = new Student("fff", 21, 88);
array.Add(st);
st = new Student("ddd", 21, 88);
array.Add(st);
Console.WriteLine("Before Sort:");
foreach (Student s in array)
{
Console.WriteLine(s.sname + "\t" + s.sage + "\t" + s.score);
}
array.Sort();
Console.WriteLine("After Sort:");
foreach (Student s in array)
{
Console.WriteLine(s.sname + "\t" + s.sage + "\t" + s.score);
}
}
}
struct Student : IComparable
{
public string sname;
public int sage;
public int score;
public Student(string sname, int sage, int score)
{
this.sname = sname;
this.sage = sage;
this.score = score;
}
public int CompareTo(object obj)
{
Student st = (Student)obj;
if (this.score != st.score)
return st.score.CompareTo(this.score);
if (this.sage != st.sage)
return this.sage.CompareTo(st.sage);
if (this.sname != st.sname)
return this.sname.CompareTo(st.sname);
return 1;
}
}