C# 7.3 Enum constraint: Why can't I use the nullable enum?

前端 未结 2 825
心在旅途
心在旅途 2020-12-25 10:34

Now that we have enum constraint, why doesn\'t compiler allow me to write this code?

public static TResult? ToEnum(this String value, TResult?         


        
2条回答
  •  旧巷少年郎
    2020-12-25 10:58

    You can, but you have to add another constraint: the struct constraint.

    public static void DoSomething(T? defaultValue) where T : struct, Enum
    {
    }
    

提交回复
热议问题