Now that we have enum constraint, why doesn\'t compiler allow me to write this code?
public static TResult? ToEnum(this String value, TResult?
Because System.Enum
is a class, you cannot declare a variable of type Nullable
(since Nullable
is only possible if T
is a struct
).
Thus:
Enum? bob = null;
won't compile, and neither will your code.
This is definitely strange (since Enum
itself is a class, but a specific Enum
that you define in your code is a struct
) if you haven't run into it before, but it is clearly a class
(not a struct
) as per the docs and the source code.