Converting enum values into an string array
Enum.GetValues
will give you an array with all the defined values of your Enum
. To turn them into numeric strings you will need to cast to int
and then ToString()
them
Something like:
var vals = Enum.GetValues(typeof(VehicleData))
.Cast<int>()
.Select(x => x.ToString())
.ToArray();
Demo
Use GetValues
Enum.GetValues(typeof(VehicleData))
.Cast<int>()
.Select(x => x.ToString())
.ToArray();
Live demo
What about Enum.GetNames?
string[] cars = System.Enum.GetNames( typeof( VehicleData ) );
Give it a try ;)
I found this here - How do I convert an enum to a list in C#?, modified to make array.
Enum.GetValues(typeof(VehicleData))
.Cast<int>()
.Select(v => v.ToString())
.ToArray();