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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -