How to get an array of all enum values in C#?
This gets you a plain array of the enum values using Enum.GetValues
:
var valuesAsArray = Enum.GetValues(typeof(Enumnum));
And this gets you a generic list:
var valuesAsList = Enum.GetValues(typeof(Enumnum)).Cast<Enumnum>().ToList();
Try this code:
Enum.GetNames(typeof(Enumnum));
This return a string[]
with all the enum names of the chosen enum.
Enum.GetValues(typeof(Enumnum));
returns an array of the values in the Enum.
You may want to do like this:
public enum Enumnum {
TypeA = 11,
TypeB = 22,
TypeC = 33,
TypeD = 44
}
All int values of this enum
is 11,22,33,44
.
You can get these values by this:
var enumsValues = Enum.GetValues(typeof(Enumnum)).Cast<Enumnum>().ToList().Select(e => (int)e);
string.Join(",", enumsValues)
is 11,22,33,44
.
Something little different:
typeof(SomeEnum).GetEnumValues();