|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace xUnitStudy.Model
|
|
|
|
namespace xUnitStudy.Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class Person:IPerson,IEqualityComparer<Person>
|
|
|
|
public class Person:IPerson,IEqualityComparer<Person>,IComparer<Person>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public int Id { get; set; }
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
|
@ -27,5 +27,27 @@ namespace xUnitStudy.Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return obj.Id;
|
|
|
|
return obj.Id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// IComparer接口实现
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="x">比较对象1</param>
|
|
|
|
|
|
|
|
/// <param name="y">比较对象2</param>
|
|
|
|
|
|
|
|
/// <returns>x小于y则返回负整数;x大于y则返回正整数;x等于y则返回0</returns>
|
|
|
|
|
|
|
|
public int Compare(Person x, Person y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (x.Id < y.Id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (x.Id == y.Id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|