Using the string value of a C# enum value in a case statement

I prefer to use enums instead of string in my projects, I think it’s better way rather than hard coding the string.

I can define the enums as below

If you want to shorten the namespace you can use this

Then you can use the switch statement like this

if you also want to validate the enum you can wrap it with a Enum.IsDefined check


Leave a comment