考虑以下类:
public class Transition<TState>
{
public Transition ()
{
if (!typeof(TState).IsEnum)
throw (new ArgumentException("[TState] has to be of type [System.Enum]."));
}
}
理想情况下,这应该声明为:
public class Transition<TState> where TState: System.Enum
{
}
当然,上述内容会产生编译时错误。我的问题是为什么这被定为非法。大多数消息来源解释说这是非法的,但没有解释原因。有什么想法吗?