Nullable< bool>的用途是什么?类型? [英] What is the use of Nullable<bool> type?

查看:109
本文介绍了Nullable< bool>的用途是什么?类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bool 变量可以为true或false,而 bool?也可以为null.

a bool variable could hold true or false, while bool? could be null as well.

为什么我们需要bool的第三个值? 如果不是 true ,那就等于== false

Why would we need a third value for bool ? If it is not true, what ever it is, it is == false

您能提出一个我更喜欢布尔的情况吗?.

Can you suggest a scenario where I would fancy a bool? instead.

谢谢

推荐答案

出于多种原因,某些事情可能是正确的,错误的或不确定的.一个人怎么回答你的第三个孩子是女孩吗?"如果一个人只有两个孩子?正确和错误均不正确.如果说比较不适用,则以Null为宜.

Something can be true, false or undefined for many reasons. How would one answer "Is your third child a girl?" if one only has two children? Both true and false are incorrect. Null would be appropriate as saying that the comparison doesn't apply.

这篇关于Nullable< bool>的用途是什么?类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆