Possible Duplicate:
Create Generic method constraining T to an Enum
Enum type constraints in C#
Consider the following class:
public class Transition<TState> { public Transition () { if (!typeof(TState).IsEnum) throw (new ArgumentException("[TState] has to be of type [System.Enum].")); } } Ideally, this should be declared as:
public class Transition<TState> where TState: System.Enum { } The above, of course, generates a compile-time error. My question is why has that been made illegal. Most sources explain say that it is illegal but do not explain why. Any thoughts?