当我反向工程我的类时,我得到以下内容:
public Nullable<bool> Correct { get; set; }
public Nullable<bool> Response { get; set; }
I coded:
public bool? Correct { get; set; }
public bool? Response { get; set; }
有人能告诉我这两者之间是否有任何区别吗?我以前没有见过Nullable<bool>
,不确定为什么它不直接创建一个"bool"。
注意:根据Jon的评论,我已经将我的代码更改为bool?。
public bool? Correct { get; set; }
。编译器不会自动将bool
转换为bool?
。 - Jon Skeetbool?
而是bool
吗? - Robert Rouhanibool?
- 这应该是一个提示,告诉您没有区别 - 反向工程工具无法知道您写了哪个。 - Damien_The_Unbelieverbool?
只是 C# 编译器为了方便而定义的别名。 - CodesInChaos