//BaseHotelInfoEntity是一个继承BaseEntity的子类 c#
public class BaseEntityEqualityComparer : IEqualityComparer<BaseHotelInfoEntity> { public bool Equals(BaseHotelInfoEntity x, BaseHotelInfoEntity y) { return ((BaseEntity)x).Id == ((BaseEntity)y).Id; } public int GetHashCode(BaseHotelInfoEntity obj) { return obj.ToString().GetHashCode(); } }
hotels = hotels.Distinct(new BaseEntityEqualityComparer()).ToList();