IComparer 比较器:实现动态排序,可以指定某个项排序
class AgeASC : IComparer<Student>
{
public int Compare(Student x, Student y)
{
return x.Age - y.Age;
}
}
升序:大于 0
降序:小于 0
IComparable 比较接口:只能指定一个对比项
class Student : IComparable<Student>
{
public int CompareTo(Student other)
{
return other.stuName.CompareTo(this.stuName);
}
}
升序:other 在前面 this 在后面
降序:this 在前面 other 在后面