I am curious and I want to get rid of the doubt, in which cases a variable is declared in the following way:
public short? Secuendia {get; set;}
What does the question mark mean and in which cases the data type is accompanied by a character?
I am curious and I want to get rid of the doubt, in which cases a variable is declared in the following way:
public short? Secuendia {get; set;}
What does the question mark mean and in which cases the data type is accompanied by a character?
The character
?
is used in types to indicate the value is nullable , that is, it can be a valid number or it can be null.They are known as Nullable Types , and can represent the normal range of numbers of the specified type plus the null value.
In practice they are instances of the structure
System.Nullable<T>
, therefore it has some methods.Example:
In Booleans, it is used to represent tristate or three-state values.
The type declaration
?
is used when you use a data type that cannot be,null
for example, a Structure and you force it to benull
, this is achieved by marking with the operator?
This is called Nullable
You can check more here: Operator ??
Difference against a normal statement