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

后端 未结 5 1024
南旧
南旧 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:28

    As Mehrdad says, you can't do that on the enum itself. You could however make a couple of extension methods that work on your enum. That will make it look like methods on the enum.

    static bool IsLessThan(this SizeType first, SizeType second) {
    }
    

提交回复
热议问题