Variable type ending with ?

.net, c#, nullable, types

Solution

`?` makes your non-nullable (value) types nullable. It doesn't work for `string`, as it is reference type and therefore nullable by default.

From MSDN, about value types:

Unlike reference types, a value type cannot contain the null value. However, the nullable types feature does allow for values types to be assigned to null.

`?` is basically a shorthand for `Nullable<T> structure`.

If you want to know more, MSDN has a great article regarding this topic.

Problem

What does `?` mean: ``` public bool? Verbose { get; set; } ``` When applied to `string?`, there is an error: 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'

Original source

Related problems