C#C
C#3y ago
__dil__

❔ Generics and nullable types

This snippet below results in an error

class Foo<T>
{
    T? _foo;

    Foo()
    {
        _foo = null; // Error here
    }
}

Cannot convert null to type parameter 'T' because it could be a value type. Consider using 'default(T)' instead.

I don't really understand the error. I thought the type of _foo was T?, not T.
Was this page helpful?