(2)在Main函数中,定义一个List集合students用以存放Student类的
若干(2个)实例,调用List的sort方法, 根据Student的id排序,遍历集合,输出排序后的学号及姓名。
public Program
{
public class Listwhere T:IComparable
{
}
static void Main()
{
}
}
public class Student : IComparable<Student >
{
public int CompareTo(Student other)
{
return this.id.CompareTo(other.id);
}
}
然后在main里面 list.sort()