考虑以下代码:
class Employee : IComparable<Employee>
{
public string Name { get; set; }
public int CompareTo(Employee other)
{
return string.Compare(this.Name, other.Name);
}
}
void DoStuff()
{
var e1 = new Employee() { Name = "Frank" };
var e2 = new Employee() { Name = "Rizzo" };
var lst = new List<Employee>() { e1, e2 };
lst.Sort();
}
我怎么知道 Sort 方法是否真的重新排列了任何东西?额外的问题:如果重新排列,有多少东西?