snippetcsharpCritical
How do I convert an enum to a list in C#?
Viewed 0 times
listenumconverthow
Problem
Is there a way to convert an
enum to a list that contains all the enum's options?Solution
This will return an
If you want that to be a
To use the Cast function on an Array you need to have the
IEnumerable of all the values of an Enum.Enum.GetValues(typeof(SomeEnum)).Cast();If you want that to be a
List, just add .ToList() after .Cast().To use the Cast function on an Array you need to have the
System.Linq in your using section.Code Snippets
Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();Context
Stack Overflow Q#1167361, score: 1371
Revisions (0)
No revisions yet.