Why can't I fill the default generic property with the value null if the property is nullable and the generic type is not restricted in any way?
public class Class_0<TValue> where TValue : struct
{
public TValue? Value { get; } = null; // is valid
}
public class Class_1<TValue> where TValue : class
{
public TValue? Value { get; } = null; // is valid
}
public class Class_2<TValue>
{
public TValue? Value { get; } = null; // error
}
I need the property to be able to be either struct or class and always be filled with the value null. I can't write something like this: where TValue : struct, class.
public TValue? Value { get; } = default;thennew Class_2<int>()will write null value 0 instead of null to the nullable property.