What's the difference between “bool” and “bool?”?

后端 未结 8 1772
栀梦
栀梦 2020-12-08 12:44

I use the \"bool\" type for variables as I was used to in C++, and I try to put the values of functions or properties I expect to be boolean into my variable. However I ofte

相关标签:
8条回答
  • 2020-12-08 13:43

    bool means you can have values of true and false. bool? means you can have a value of true, false, and null.

    It works for datetime and booleans.

    0 讨论(0)
  • 2020-12-08 13:46

    bool? means the boolean is nullable and is syntactic sugar for a stucture Nullable<bool>. Because a boolean is a value type, you cannot set it to null, but there are some cases where you'd want to like in a data access class because database fields can have null values.

    0 讨论(0)
提交回复
热议问题