The code demo is outlined here: https://dotnetfiddle.net/mCm8Hx
If I have a class that overrides Equals and operators == and !=, I can compare them via variables typed as that class.
But if I cast them to object (or use variables typed as object that are assigned to instances of that class), the operator doesn't seem to be used anymore.
E.g. this would work:
var a1 = new MyClass(5);
var a2 = new MyClass(5);
Console.WriteLine(a1 == a2); // prints "true" because I've implemented == operator
This also works (MySubClass : MyClass):
var b1 = new MySubClass(10);
var b2 = new MySubClass(10);
Console.WriteLine(b1 == b2); // prints "true" because I've implemented == operator in inherited class MyClass
But this doesn't:
object o1 = a1;
object o2 = a2;
Console.WriteLine(o1 == o2); //prints "false", doesn't use my operator implementation
Since all classes inherit implicitly from Object, I'd expect it to work the same way as it works with MySubClass. Why this isn't the case with object typed vars?
