//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();