I have the following example:
namespace ComparisonExample
{
class Program
{
static void Main(string[] args)
{
var hello1 = new Hello();
var hello2 = new Hello();
// calls Hello.Equals
var compareExplicitly = hello1.Equals(hello2);
// calls Object.Equals
var compareWithGenerics = ObjectsEqual<Hello>(hello1, hello2);
}
private static bool ObjectsEqual<TValue>(TValue value1, TValue value2)
{
return value1.Equals(value2);
}
}
class Hello : IEquatable<Hello>
{
public bool Equals(Hello other)
{
return true; // doesn't matter
}
}
}
The question is why in the second "Equals" call I'm redirected to Object.Equals instead of Hello.Equals even though I'm specifying the exact type in generic argument?