Add where T : struct
generic constraint to get rid of the error since Nullable<T>
accepts only struct
.
public class MySuperCoolClass<T> where T : struct
{
public T? myMaybeNullField { get; set; }
}
Nullable<T>
is defined as below
public struct Nullable<T> where T : struct
So you're also forced to do so, just to prevent you from doing MySuperCoolClass<object>
which makes object?
which is not valid.