Say i have the following Enum Values
enum Language
{
CSharp= 0,
Java = 1,
VB = 2
}
I would like to convert them to list of values (i.e) { CSharp,Java,VB}.
How to convert them to a list of values?
Say i have the following Enum Values
enum Language
{
CSharp= 0,
Java = 1,
VB = 2
}
I would like to convert them to list of values (i.e) { CSharp,Java,VB}.
How to convert them to a list of values?
If I understand your requirement correctly , you are looking for something like this
var enumList = Enum.GetValues(typeof(Language)).OfType<Language>().ToList();
OfType<Language>().ToList() when you can just cast it straight to a Languages[]?You can use this code
static void Main(string[] args)
{
enum Days { Sat, Sun, Mon, Tue, Wed, Thu, Fri };
Array arr = Enum.GetValues(typeof(Days));
List<string> lstDays = new List<string>(arr.Length);
for (int i = 0; i < arr.Length; i++)
{
lstDays.Add(arr.GetValue(i).ToString());
}
}