Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate through an enum in C#? [duplicate]

Tags:

c#

enums

I want to iterate through an enum so I can call a method with each value of that enum. How can I do that?

enum Base { ANC, BTC, DGC };

XmlDocument doc;

doc = vircurex.get_lowest_ask(Base.ANC)
doc = vircurex.get_lowest_ask(Base.BTC)
doc = vircurex.get_lowest_ask(Base.DGC)

I want it instead to be something like

foreach (var val in values)
   doc = vircurex.get_lowest_ask(....)

Is there a way to do this?

like image 817
Kasper Hansen Avatar asked Jan 08 '14 15:01

Kasper Hansen


1 Answers

Try

foreach(var base in Enum.GetValues(typeof(Base)).Cast<Base>()) 
{
    doc = vircurex.get_lowest_ask(base)
}
like image 130
Moeri Avatar answered Nov 02 '22 23:11

Moeri