If reference type doesn’t overload an equality operator ==, then build-in equality operator on Object will be used instead. Why isn’t the same true for user-defined structs:
struct A{ }
static void Main(string[] args)
{
A a = new A();
A a1 = new A();
bool equal= (a == a1); //error
}
Namely, doesn’t ValueType ( from which all structs derive ) also overload == operator?
How would such a default == operator work? For reference types, comparing adresses is reasonable, but since that check will never be true for two ValueTypes (since if two ValueTypes are in scope then they are guaranteed to have different locations on the stack,) address comparison is pointless.
As the compiler has helpfully pointed out, ValueType very intentionally does not have a default == operator.