IComparer<T> is implemented by types that are capable of comparing 2 different values, whereas an instance of IComparable<T> is capable of comparing _itself_ with another value.
例如
public class Employee_ClassB : IComparable<Employee_ClassB>
{
public Employee_ClassB() { Name = "hello from Class B"; }
public Employee_ClassB(string Name) { this.Name = Name; }
public string Name { get; set; }
public int CompareTo(Employee_ClassB obj)
{
return Name.CompareTo(obj.Name);
}
}
public class EmployeeComparer : IComparer<Employee_ClassB>
{
public int Compare(Employee_ClassB x, Employee_ClassB y)
{
return x.CompareTo(y);
}
}
...