无法确定条件表达式的类型,因为有'廉政'之间的隐式转换'<&空GT;' [英] Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and '<null>'
本文介绍了无法确定条件表达式的类型,因为有'廉政'之间的隐式转换'<&空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;
这篇关于无法确定条件表达式的类型,因为有'廉政'之间的隐式转换'<&空GT;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文