public class FillOneDollarShareComparer : IEqualityComparer<FillOneDollarShareEntity> { // Products are equal if their names and product numbers are equal. public bool Equals(FillOneDollarShareEntity x, FillOneDollarShareEntity y) { //Check whether the compared objects reference the same data. if (ReferenceEquals(x, y)) return true; //Check whether any of the compared objects is null. if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; //Check whether the products' properties are equal. return x.id == y.id; } // If Equals() returns true for a pair of objects // then GetHashCode() must return the same value for these objects. public int GetHashCode(FillOneDollarShareEntity entity) { //Check whether the object is null if (ReferenceEquals(entity, null)) return 0; //Get hash code for the Name field if it is not null. int hashID = entity.id.GetHashCode(); //Calculate the hash code for the product. return hashID; } }