相关疑难解决方法(0)

如何使用Nullable Int的条件运算

一个小问题.任何想法的人为什么这不起作用?

int? nullableIntVal = (this.Policy == null) ? null : 1;
Run Code Online (Sandbox Code Playgroud)

null如果左手表达式为True,我试图返回,否则1.看似简单,但给出了编译错误.

无法确定条件表达式的类型,因为null和之间没有隐式转换int.

如果我用任何有效的替换nullin ,那么没有问题.? null : 1int

c# nullable conditional-operator

8
推荐指数
1
解决办法
1318
查看次数

标签 统计

c# ×1

conditional-operator ×1

nullable ×1