7

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?

1

1 Answer 1

4

Try

foreach(var base in Enum.GetValues(typeof(Base)).Cast<Base>()) 
{
    doc = vircurex.get_lowest_ask(base)
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.