[Solved-4 Solutions] C# nullable string error
- Later in the code we use it like this:
- We get the following error at the declaration of typeOfContract line stating:
- The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>'
- System.String is a reference type and already "nullable".
- Nullable<T> and the ? suffix are for value types such as Int32, Double, DateTime, etc.
- You are making it complicated. string is already nullable. You don't need to make it morenullable. Take out the ? on the property type.
- string cannot be the parameter to Nullable because string is not a value type. String is a reference type.
- is a very valid statement and there is not need to make it nullable.
- For nullable, use ? with all of the C# primitives, except for string.