I know the importance of overriding GetHashCode when implementing custom equality checks – for which I have implemented IEquality<T> interface, and also the difference between generic and non-generic Equals as discussed here. Now is there a point to override Equals(object t)? Wouldn’t everything come under generic Equals(T t)?
public override int GetHashCode() //required for hashsets and dictionaries
{
return Id;
}
public bool Equals(T other) //IEquatable<T> here
{
return Id == other.Id;
}
public override bool Equals(object obj) //required??
{
return Equals(obj as T);
}
From msdn:
I could have done a better google search too. Here’s a good article on msdn blogs by JaredPar on the subject.
In short, overriding
Equals(object obj):Accepting this since the link is more thorough on the subject. Thanks to Oded too..