In C#, I just call
ToString
to get the name. It's quicker and dirtier...
namespace EnumTest
{
using System;
using System.Linq;
enum ListOfChoices : int
{
Yes,
No,
Possibly,
Never,
Pass
}
class Program
{
static void Main(string[] args)
{
ListOfChoices choice1 = ListOfChoices.Never;
string choice1Name = choice1.ToString();
Console.WriteLine("choice1 name = " + choice1Name);
Console.WriteLine("choice1 name = " + choice1);
string[] allChoiceNames = Enum.GetNames(typeof(ListOfChoices));
Console.WriteLine();
Console.WriteLine(string.Join(Environment.NewLine, allChoiceNames));
int[] allValues = Enum.GetValues(typeof(ListOfChoices)).Cast<int>().ToArray();
Console.WriteLine();
for (int ndx = 0; ndx < allValues.Length; ndx++)
{
Console.WriteLine(allValues[ndx]);
}
Console.ReadKey(true);
}
}
}
</int>
Console Output:
choice1 name = Never
choice1 name = Never
Yes
No
Possibly
Never
Pass
0
1
2
3
4