Could someone explain why this works in C#.NET 2.0:
Nullable<DateTime> foo;
if (true)
foo = null;
else
foo = new DateTime(0);
...but this doesn't:
Nullable<DateTime> foo;
foo = true ? null : new DateTime(0);
The latter form gives me an compile error "Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'System.DateTime'."
Not that I can't use the former, but the second style is more consistent with the rest of my code.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…