c# - How do I enumerate an enum? -
how can enumerate enum
in c#?
e.g. following code not compile:
public enum suit { spades, hearts, clubs, diamonds } public void enumerateallsuitsdemomethod() { foreach (suit suit in suit) { dosomething(suit); } }
and gives following compile-time error:
'suit' 'type' used 'variable'
it fails on suit
keyword, second one.
foreach (suit suit in enum.getvalues(typeof(suit))) { // ... }
Comments
Post a Comment