Given a type parameter which is a Nullable<>
, how can I create an instance of that type which has HasValue = false
?
In other words, compl
Highly dangerous (and not recommended for non-testing purposes) is to use SharpUtils' method UnsafeTools.Box
. It bypasses the normal boxing of nullable types, which boxes their value or returns null, and instead creates an actual instance of Nullable
. Note that working with such an instance can be extremely buggy.
public static object Create() where T : struct //T must be a normal struct, not nullable
{
return UnsafeTools.Box(default(T?));
}