.NET 3.5 makes it simple by using extension methods:
enum Color {Red, Green, Blue}
Can be iterated with
Enum.GetValues(typeof(Color)).Cast()
or define a new static generic method:
static IEnumerable GetValues() {
return Enum.GetValues(typeof(T)).Cast();
}
Keep in mind that iterating with the Enum.GetValues() method uses reflection and thus has performance penalties.