I know the following is not possible because it has to be an int
enum GroupTypes
{
TheGroup = "OEM",
TheOtherGroup = "CMB"
}
From my database I get a field with incomprehensive codes (the OEM and CMB's). I would want to make this field into an enum or something else understandable. Because the target is readability the solution should be terse.
What other options do I have?
Try adding constants to a static class. You do not end up with a Type, but you have readable, organised constants:
C# doesn't support enumerated strings, but for most situations you can use a List or Dictionary to get the desired effect.
E.g. To print pass/fail results:
Another way to deal with the problem, is to have a enum and a array of strings that will map the enum values with the list of strings:
you may use it something like this:
It will prompt CMB
PROS:
CONS:
I like to use properties in a class instead of methods, since they look more enum-like.
Here's a example for a Logger:
Pass in type-safe string values as a parameter:
Usage:
In VS 2015, you can use nameof
Usage:
If you're trying to make your code readable:
and if you need a list of them, include these finals in a static final List<String>. This example is in Java.
If you're trying to make your application readable, add: