【发布时间】:2018-11-16 10:11:32
【问题描述】:
当我对我的课程进行逆向工程时,我得到以下信息:
public Nullable<bool> Correct { get; set; }
public Nullable<bool> Response { get; set; }
我编码:
public bool? Correct { get; set; }
public bool? Response { get; set; }
谁能告诉我这两者之间是否有任何区别。我之前没有见过Nullable<bool>,我不确定它为什么不只是创建一个“布尔”。
注意:我将编码更改为布尔值?乔恩对 cmets 的回应
【问题讨论】:
-
我怀疑你实际上编码了
public bool? Correct { get; set; }。编译器不会自动将bool转换为bool?。 -
你确定你写的不是
bool?而不是bool? -
我注意到 Nullable
需要 System 命名空间但是 bool?才不是。有人知道那是什么吗? -
如果您使用不同的工具对代码进行逆向工程,它可能会返回
bool?- 这应该向您暗示没有区别 - 逆向工程工具无法知道两者中的哪一个你写的。 -
bool?只是 C# 编译器为方便起见而定义的别名。
标签: c#