Convert all Enum value to a List
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class EnumUtil
{
public static List<T> ToList<T>()
{
Type enumType = typeof(T);
if (enumType.BaseType != typeof(Enum))
throw new ArgumentException("T must be of type System.Enum");
Array enumValArray = Enum.GetValues(enumType);
List<T> enumValList = new List<T>(enumValArray.Length);
foreach (int val in enumValArray)
{
enumValList.Add((T)Enum.Parse(enumType, val.ToString()));
}
return enumValList;
}
}
Related examples in the same category