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

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -