tags:

views:

3253

answers:

2

Is there a way to convert an enum to a list that contains all the enum's options?

+22  A: 

This will return an array of all the values of an Enum.

Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();
Jake Pearson
that was easy...
nice.. its is workingArray arr = (Array) Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>(); Is this right to work this code line?
Lalit
Actually the result of Cast<T>() is an IEnumerable<T> so if you want an array you would have to change your line to:`var array = Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>().ToArray();`
Jake Pearson
+3  A: 

I think that if you are looking to do this, you might want to think if you really should be using an enum or if you should switch to an object that represents w/e your enum is.

Bryan Rowe