I have a simple enum:
enum E
{
FullNameForA = 1,
A = 1,
FullNameForB = 2,
B = 2
}
The goal is to be able to use different string values for the same integral values with a twist – FullNameFor* must be used as default. In other words, a user can provide E.A as an input but the code should use E.FullNameForA for output.
It seems like by default C# will use alphabetical ordering of elements with the same integral value, which makes my goal harder. Is that right? Any ideas how to overcome this?
In what context? When you convert the value back to a string? From the docs of
Enum.ToString:(Note that the decision is in the BCL – it’s not a language decision.)
I suggest that if you want a canonical string representation for each value, you create a
Dictionary<E, string>and consult that rather than callingToString().