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

Asked

Viewed 167 times

15

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

Example:

public bool? Status

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

1 answer

16


This is syntactic sugar for nullables (cancellable types). Equals:

public Nullable<bool> Status

It is 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, cannot contain null references.

More information in the manual.

  • 1

    Hmmm.... got good answer I will use this to be able to make comparisons of nulls. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.