private static IEnumerable<T> GetEnumValues<T>(){// Can't use type constraints on value types, so have to do check like thisif (typeof(T).BaseType != typeof(Enum)){throw new ArgumentException("T must be of type System.Enum");}
return Enum.GetValues(typeof(T)).Cast<T>();}
static void Main(string[] args){foreach (int value in Enum.GetValues(typeof(DaysOfWeek))){Console.WriteLine(((DaysOfWeek)value).ToString());}
foreach (string value in Enum.GetNames(typeof(DaysOfWeek))){Console.WriteLine(value);}Console.ReadLine();}
public enum DaysOfWeek{monday,tuesday,wednesday}