Can I overload an == operator on an Interface?

No, you can't. Overloading == requires static methods in one of the types you use, and an interface can't contain those. Extension methods can't help either. So on interfaces == is always using reference equality.

Note that a.Equals(b) will throw an exception if a==null.


No, you can neither overload an operator on an interface, nor ensure that any implementors do so (as operator overloading is static in C# ).

Your best option is what you've done, to make IFoo inherit from IEquatable<IFoo> and use Equals(IFoo)


Besides CodeInChaos' answer you may be interested in reading Guidelines for Overriding Equals() and Operator ==.