So the underlying principle here is that Equals
is a virtual instance method of every type, meaning it will use the vtable to determine the implementation to use, at runtime, based on the type of the actual object that called Equals
(disregarding the type of the variable).
operator ==
can be thought of as a static method (with a lot of overloads). It is not virtual, so the implementation that is referred to will be based on the compile time type of the variable holding the object, and won't be based on what the actual type of the object is at runtime.
This behavior can be replicated by simply creating your own static
Equals
methods (on whatever type or types you prefer) that behave based on the types of the two arguments. This is slightly less convenient to type out than using operator ==
, but does effectively the same thing once compiled.