C# basics: can I overload operators for enums?

Posted: (EET/GMT+2)

 

In C#, operator overloading is a very useful feature, and you've probably implemented your own overrides in the classes you've written.

Today, I ran into an interesting question: can you overload operators for an "enum" type? The short answer is, unfortunately, no. The operator overloading feature in C# is only available for classes or structs.

But, you could write extension methods that work with your enums to almost give similar possibilities.

Hope this helps!