You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
public class Person:IPerson,IEqualityComparer<Person>,IComparer<Person>
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string GetFullName()
{
return FirstName + "_" + LastName;
}
public bool Equals(Person x, Person y)
{
return x.Id == y.Id;
}
public int GetHashCode(Person obj)
{
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;
}
}
}
}