How do I override the equals operator == for an Interface in C#?

前端 未结 4 1185

I have defined the following interface

public interface IHaveAProblem
{
    string Issue { get; set; }
}

And here is the implementation of

4条回答
  •  耶瑟儿~
    2021-01-03 23:19

    The operator == is static. You cannot define static methods for interfaces in C#. Also, for all operators at least one of the argument types needs to be of the same type as the class it is defined in, therefore: No operator overloading for interfaces :(

    What you CAN do is use an abstract class instead - and define the operator there. Again, the operator may NOT be virtual (since static methods cannot be virtual...)

    [Edited, reason see comment.]

提交回复
热议问题