Because you did not tell the universal method that your object implements IEquatable<T> :
Try now:
private static bool ObjectsEqual<TValue>(TValue value1, TValue value2) where TValue : IEquatable<TValue>
In your ObjectsEqual method, you only have access to the TValue methods / properties / fields that are defined in the object class plus the methods that are defined in the interface / base class classes defined in the restrictions. No restrictions => you only have access to Equals(object) , GetHashCode() , GetType() , (and if you have a class restriction: operator== , operator!= .) Of these two virtual ( Equals(object) , GetHashCode() ), so you will use the "correct" version, the third will not usually be overwritten ( GetType() ), so you will probably use the "correct" version. Only two operators == / != Are often overwritten, and there you go! In your general method, you cannot use the βcorrectβ version of these two !:-)
source share