C# Method – Convert an Enum into an Enumerable

This useful method converts an Enum into an enumerable of enum values.

Enumerables are useful because you can iterate over them (foreach or linq).

public static IEnumerable<TEnum> Enum<TEnum>()
{
    return System.Enum
           .GetValues(typeof(TEnum))
           .Cast<TEnum>();
}
Advertisements

About this entry