IEqualityComparer

时间:2021-10-13 08:13:39

在linq中使用union和distinct都不起作用,结果发现必须传入一个实现了IEqualityComparer<T>的比较器

    public class CompareUser : IEqualityComparer<UserEntity>
{
public bool Equals(UserEntity x, UserEntity y)
{
if (x == null && y == null)
return false;
return x.Initial == y.Initial;
} public int GetHashCode(UserEntity obj)
{
return obj.ToString().GetHashCode();
}
}