I'm trying to do something like this:
public class MySuperCoolClass<T>
{
public T? myMaybeNullField {get; set;}
}
Is this possible?
This gives me the error:
error CS0453: The type
T' must be a non-nullable value type in order to use it as type parameter
T' in the generic type or method System.Nullable'.
Thanks
Do you see your job ?
Add
where T : struct
generic constraint to get rid of the error sinceNullable<T>
accepts onlystruct
.Nullable<T>
is defined as belowSo you're also forced to do so, just to prevent you from doing
MySuperCoolClass<object>
which makesobject?
which is not valid.