C# - 10 - String enums.

[C# 2.0]

Enums are useful but sometimes you want them to have string values. Unfortunatly enums must be numeric … however, you can decorate an enum with an attribute and that can be a string.

First add the following helper module to your solution remembering to change the namespace (MyWindowsApplication) as appropriate:

Now, elsewhere in your program you can specify an enum …

And finally, in use:

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License