The ?
character is used in types of to indicate the value is nulleable , so it can be a valid number or it can be null.
Known as Nullable Types , and may represent the normal range of numbers of the specific type plus the null value.
In practice they are instances of the structure System.Nullable<T>
therefore it has some methods.
Example:
int? num = null;
// tiene valor en num
if (num.HasValue)
{
System.Console.WriteLine("num = " + num.Value);
}
else
{
System.Console.WriteLine("num = Null");
}
In Boolean it is used to represent tristate or three-state values.
bool? tristate; // puede ser true, false o null