You cannot guarantee that T itself is a NULL value type, no. However, you can ensure that T an unimaginable value type, but then use T? everywhere in the classroom.
public class Test<T> where T : struct { T? _value; public void Test(T? value) { _value = value; } public void DoStuff() { if(_value.HasValue) {
Another feature is that you cannot limit T any type of NULL, including reference types, and you cannot limit T to any type of value, including types of NULL values. The where T : class constraint only works with classes (including delegate types) and interfaces, and with the where T : struct constraint only with value types that are not null values (including enumerations).
source share