How can you enumerate an enum in C#?
enum
E.g. the following code does not compile:
public enum Suit {
If you have:
enum Suit { Spades, Hearts, Clubs, Diamonds }
This:
foreach (var e in Enum.GetValues(typeof(Suit))) { Console.WriteLine(e.ToString() + " = " + (int)e); }
Will output:
Spades = 0 Hearts = 1 Clubs = 2 Diamonds = 3