Click here to Skip to main content
15,068,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<t>'

What I have tried:

I tried setting the parameter and got the message above from
String? prob = record.GetValueString(_Prbblty);
Updated 17-May-21 8:41am

String is not a value type - it's a reference type which means it can contain null values already.

You can only declare nullable variables if they are value types (int, float, double, ... or struct rather than class based).

That's what the error message is saying, but in a roundabout way because of how it is implemented as a "Nullable<T>" with syntactic sugar you type as "T?"
All reference types are nullable; String is considered a reference type; you can already assign null to a string.

At some point, string? will mean that you want a nullable "reference" to a string; and not an actual null string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900