无法确定条件表达式的类型,因为有'廉政'之间的隐式转换'<&空GT;'
问题描述:
这是我的代码:
int? BankName_dd =
int.Parse((e.Item.FindControl("BankName_dd") as DropDownList).SelectedValue) != -1 ?
int.Parse((e.Item.FindControl("BankName_dd") as DropDownList).SelectedValue) : null;
但我不明白为什么这个错误被提出任何建议?
but I don't understand why this error is being raised any suggestions ?
答
这是因为编译器试图先评估右侧。
it happens because compiler tries to evaluate the right hand side first.
int.Parse((e.Item.FindControl(BankName_dd)as DropDownList).SelectedValue)
是int且不可为空,因此参数之间不匹配ie int和null
int.Parse((e.Item.FindControl("BankName_dd") as DropDownList).SelectedValue)
is int and not nullable so there is a mismatch between parameters i.e int and null
即使这样做也不错。现在将第一个参数清除为null int
Even this would be fine if you do it. this now wakes the first parameter as nullable int
int? BankName_dd = int.Parse((e.Item.FindControl("BankName_dd") as DropDownList).SelectedValue) != -1 ? (int?)int.Parse((e.Item.FindControl("BankName_dd") as DropDownList).SelectedValue):null;