This code:
public T Foo<T>()
where T : class?
{
return null;
}
Gives a following error:
A null literal introduces a null value when 'T' is a non-nullable reference type
I don't see why we can't return null when we say that T can be nullable. If we additionally try to return T?
we will get an error that T
has to be non-nullable.
It seems it's kind of impossible to have a nullable constraint and return a nullable result at the same time.