可能重复:
Nullable types and the ternary operator. Why won’t this work?C#可空类型的问题
例如:
int? taxid;
if (ddlProductTax.SelectedValue == "") {
taxid = null; }
else {
taxid = Convert.ToInt32(ddlProductTax.SelectedValue);
} //Correct
但
int? taxid;
taxid = (ddlProductTax.SelectedValue == "" ? null : Convert.ToInt32(ddlProductTax.SelectedValue)); //Error
它错误说和int32不能隐式转换。
(?truepart:falsepart);不缺少(如果..ELSE ..)?
@Gishu,精确复制我说。 @TatMing检查链接副本的答案。 – Paolo 2010-06-11 07:16:36
Eric Lippert在最近的博客文章中提到:[http://blogs.msdn.com/b/ericlippert/archive/2010/05/27/cast-operators-do-not-obey-the-distributive-law。 ASPX](http://blogs.msdn.com/b/ericlippert/archive/2010/05/27/cast-operators-do-not-obey-the-distributive-law.aspx) – benPearce 2010-06-11 07:19:01