Convert Enum to List<> using C#
Feb 10, 2010
Question is...
A user recently asked me how to convert an Enum to a List<>.
Here's the code to do so:
Convert Enum to List<> using C#
A user recently asked me how to convert an Enum to a List<>.
Here's the code to do so:
class Program
{
enum Days { Sat, Sun, Mon, Tue, Wed, Thu, Fri };
static void Main(string[] args)
{
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());
}
}
}
Share