How do I overload an operator for an enumeration in C#?

后端 未结 5 1019
南旧
南旧 2020-12-06 04:16

I have an enumerated type that I would like to define the >, <, >=, and <= operators for. I know that these o

5条回答
  •  暖寄归人
    2020-12-06 04:38

    You can't do that. You can only provide overloaded operators for classes and structs you define -- and at least one of the parameters should be of type of the class or struct itself. That is, you can declare an overloaded addition operator that adds a MyClass to MyEnum but you can never do that with two MyEnum values.

提交回复
热议问题