Suppose I defined this enum
one where several members have the same basic value:
enum Number
{
One = 1,
Eins = 1,
Uno = 1
}
According to the MSDN documentation :
If several enumeration elements have the same base value, and you are trying to get a string representation of the name of an enumeration member based on its base value, your code should not make any assumptions about which name the method returns.
So for example
var number = Number.One;
Console.WriteLine(number);
gives me the following result:
Eins
Print all enumeration items,
Console.WriteLine($"{Number.One} {Number.Eins} {Number.Uno}");
outputs the following result:
Eins eins eins
However, taking nameof
each member,
Console.WriteLine($"{nameof(Number.One)} {nameof(Number.Eins)} {nameof(Number.Uno)}");
gives the following result:
One Eins Uno
, , enum
. , .. - Number
, , ?