Enum.TryParse unexpected behavior
Enum
s are very simple structures, but some functions like Enum.TryParse
can have unexpected behavior. In this short blog post, we discover why and what are the alternatives.
Enum
s are very simple structures, but some functions like Enum.TryParse
can have unexpected behavior. In this short blog post, we discover why and what are the alternatives.
Enumerations are one of the fundamental value types in C#. enum
's are handy if you have a constrained set of allowed values.
But the enum
type also has a lot of drawbacks. Personally, one major issue for me is that you can't define methods inside the enum. Plus, you can just pass them invalid values and it just works (Todd Howard I'm looking at you).
So why not make a lightweight alternative which removes a lot of the shortcomings of an enum
?