public class Person : IComparable<Person>
{
public string Name { get; set; }
public int Age { get; set; }
public int CompareTo(Person other)
{
int result;
if (this.Name == other.Name && this.Age == other.Age)
result = 0;
else
{
if (this.Name.CompareTo(other.Name) > 0)
{
result = 1;
}
else if (this.Name == other.Name && this.Age > other.Age)
{
result = 1;
}
else
{
result = -1;
}
}
return result;
}
}
定义person类,并继承IComparable<>接口,实现IComparable<>接口下的CompareTo()方法。
class Program
{
stat