一个小问题.任何想法的人为什么这不起作用?
int? nullableIntVal = (this.Policy == null) ? null : 1;
null如果左手表达式为True,我试图返回,否则1.看似简单,但给出了编译错误.
null
1
无法确定条件表达式的类型,因为null和之间没有隐式转换int.
int
如果我用任何有效的替换nullin ,那么没有问题.? null : 1int
? null : 1
c# nullable conditional-operator
c# ×1
conditional-operator ×1
nullable ×1