What does ?
mean:
public bool? Verbose { get; set; }
When applied to string?
, there is an error:
The ?
is shorthand for the struct below:
struct Nullable<T>
{
public bool HasValue;
public T Value;
}
You can use this struct directly, but the ?
is the shortcut syntax to make the resulting code much cleaner. Rather than typing:
Nullable<int> x = new Nullable<int>(125);
Instead, you can write:
int? x = 125;
This doesn't work with string, as a string is a Reference type and not a Value type.