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

后端 未结 8 1889
栀梦
栀梦 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:46

    bool? means the boolean is nullable and is syntactic sugar for a stucture Nullable. 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.

提交回复
热议问题