Because it still calls the polymorphic Equals method, basically.
Sample code to demonstrate another type:
using System; struct Foo { public override bool Equals(object other) { Console.WriteLine("Foo.Equals called!"); return true; } public override int GetHashCode() { return 1; } } class Program { static void Main(string[] args) { object first = new Foo(); object second = new Foo(); first.Equals(second); } }
It still prints "Foo.Equals"! because calling the Equals method on the "field" still calls Foo.Equals .
Now == not overridden, it is overloaded ... so if you write:
object first = ...; object second = ...; bool same = first == second;
This will always be compared for a reference identifier, without any code of any type.
Jon skeet
source share