What is the function of character? in variable type in C #?

15

I see many third-party codes and I often see the use of the question mark in the variable type.

Example:

public bool? Status

Can anyone explain to me the difference between not having this ? sign in the bool data type.

    
asked by anonymous 01.08.2014 / 22:33

1 answer

16

This is syntactic sugar for nullables (nullable types). Equivalent to:

public Nullable<bool> Status

It's a way for you to have a variable that can contain a null reference or a value. Types by value (integer, boolean, dates, etc.) by default can not contain null references.

More information in the manual .

    
01.08.2014 / 22:37