int? _Type;
_Type = TypeList.SelectedValue == null?null: Convert.ToInt16(TypeList.SelectedValue);
它说不能<null>隐式转换成<int>
int?不是可空整形吗??为什么不行呢??
那有什么替代方法吗??可以不用逐个If判断,比较简便呢??
_Type = TypeList.SelectedValue == null?null: Convert.ToInt16(TypeList.SelectedValue);
它说不能<null>隐式转换成<int>
int?不是可空整形吗??为什么不行呢??
那有什么替代方法吗??可以不用逐个If判断,比较简便呢??
int? 这样可以为null
看这里
_Type = TypeList.SelectedValue == null? default(int?): Convert.ToInt16(TypeList.SelectedValue);
对滴,其实就是null。
我也不明白为什么
int? value = null; 这样没有问题.
但是 int? value = (condition)? null:2; 这样就不能通过编译.