How can you enumerate a enum in C#?
e.g. the following does not compile:
public enum Suit
{
Spades,
Hearts,
Clubs,
Diamonds
}
public void EnumerateAllSuitsDemoMethod()
{
foreach (Suit suit in Suit)
{
DoSomething(suit);
}
}
It gives the compile time error: 'Suit' is a 'type' but is used like a 'variable'
It fails on the Suit keyword, the 2nd one.
Edit: Got rid of Console.WriteLine(), it was confusing people