I am writing a EqualityComparer for a LINQ distinct expression and I am not too sure about the GetHashCode overload method. Would the below code be correct? The Id property is a long primitive.
public int GetHashCode(Deal obj)
{
return ((int)obj.Id) ^ ((int)(obj.Id >> 32)); ;
}
Probably you should check whether obj
is not null. In case of null return 0
. Honestly your implementation for long
Id is completely the same as .NET Framework GetHashCode
for long
data type. In other words you can simply call obj.Id.GetHashCode()
after not null checking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With