Can I overload an == operator on an Interface?

后端 未结 4 826

I have an interface like this:

public interface IFoo
{
  int A {get;}
  int B {get;}
}

and I have multiple classes implementing IFoo.
I

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 01:12

    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 and use Equals(IFoo)

提交回复
热议问题