The == operator that you overload is not available in C #, and the line bool equal1 = a == b compares a and b by reference.
Binary operators are overridden by static methods in C #, and you need to provide this operator instead:
static bool operator==(MyClass^ a, MyClass^ b) { return a->val == b->val; }
When overriding == you must also override != . In C #, this is actually done by the compiler.
source share