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
2009-07-22 18:49:11
that was easy...
2009-07-22 18:49:58
nice.. its is workingArray arr = (Array) Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>(); Is this right to work this code line?
Lalit
2010-08-13 09:09:37
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
2010-08-13 14:14:30
+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
2009-07-22 18:51:11