I've been looking for an answer on the internet but all I've found was:
Edit: Added some items in response to the answers
For IEquatable
- I'm supposed to overload
Equals(),GetHashCode(),==and!=together. - I'm supposed to reduce redundancy via implementing
!=via==. - I'm supposed to seal the class
- I'm supposed to overload
For IComparable
- I'm supposed to overload
Equals(),GetHashCode(),<,>,<=and>=together. - In fact it is recommend to implement IEquatable when doing so
- Overload the non-generic version of IComparable
CompareTo() == 0should meanEquals() == true
- I'm supposed to overload
So I've been thinking about this:
public bool Equals(T other)
{
if ((object)other == null)
{
return false;
}
return CompareTo(other) == 0;
}
Am I overlooking something or is this ok?