创建 IEqualityComparer的接口类必须实现Equals和GetHashCode方法
public class TipComparer : IEqualityComparer<TipDetails>
{
public bool Equals(TipDetails x, TipDetails y)
{
if (Object.ReferenceEquals(x, y)) return true; if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false; return x.tiptitle == y.tiptitle;
}
public int GetHashCode(TipDetails obj)
{
if (obj == null) return ; return obj.tiptitle.GetHashCode();
}
}
Linq调用时,只需创建这个TipComparer对象即可
result.tipdetails.Distinct(new TipComparer())