能有人解释一下为什么这个在C#.NET 2.0中有效吗:
Nullable<DateTime> foo;
if (true)
foo = null;
else
foo = new DateTime(0);
...但这不会:
Nullable<DateTime> foo;
foo = true ? null : new DateTime(0);
后一种形式导致我出现编译错误:“条件表达式的类型无法确定,因为<null>和'System.DateTime'之间不存在隐式转换。”
并不是说我不能使用前一种形式,但第二种风格与我的其余代码更加一致。