How can you enumerate an enum
in C#?
E.g. the following code does not compile:
public enum Suit
{
Spades,
Hearts,
Clubs,
Diamonds
}
public void EnumerateAllSuitsDemoMethod()
{
foreach (Suit suit in Suit)
{
DoSomething(suit);
}
}
And gives the following compile-time error:
'Suit' is a 'type' but is used like a 'variable'
It fails on the Suit
keyword, the second one.
here is a working example of creating select options for a DDL
I think caching the array would speed it up considerably. It looks like you're getting a new array (through reflection) every time. Rather:
That's at least a little faster, ja?