Code Snippet: ListEnum

Written by Troy Howard

16 February 2007

Sometimes you want to list an Enum and see what it's actual numeric values are...

Well sometimes I do anyway, and when I do, I use:

 1private static void ListEnum(Type _enum) {
 2  
 3  Console.WriteLine("enum " \+ _enum.Name); 
 4  Console.WriteLine("{");
 5  
 6  string[] foo = Enum.GetNames(_enum); 
 7  Array bar = Enum.GetValues(_enum); 
 8  
 9  for(int i =0;i<foo.Length;i++) {
10    Console.WriteLine( foo[i] + " = " \+ ((int)bar.GetValue(i)).ToString() + "," ); 
11  }
12  
13  Console.WriteLine("}");
14} 

Enjoy!