Get all names from an enum type in CSharp
Description
The following code shows how to get all names from an enum type.
Example
using System;/* www . java 2 s . c om*/
enum Color
{
red,
green,
yellow
}
public class MainClass
{
public static void Main()
{
Color c = Color.red;
// or just the names
foreach (string s in Enum.GetNames(c.GetType()))
{
Console.WriteLine("Name: {0}", s);
}
}
}
The code above generates the following result.