Invalid restrictions

Does anyone know why this code does not compile?

Nullable<Nullable<int>> n = null;

I understand that Nullable has a limitation

where T : struct

But Nullable is a structure. I also know that this restriction has the restriction "The type argument must be a value type. Any value type other than Nullable can be specified." ( https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters ). So how does it work? Is this solved at the compiler level?

+6
source share
1 answer

Error message:

The type int?must be an invalid value type in order to use it as the 'T' parameter in a generic type or methodNullable<T>

, , , . Nullable<int> - .

CS0453, :

, non-value , . , .

Q: ?

, , " , . , #.


?

, Nullable<Nulable<int>>? Nullables, null ( undefined, ). Nullable<int>, null. , , . , Nullable<string>, , null.

+5

All Articles