【发布时间】:2014-08-21 17:45:51
【问题描述】:
是否可以创建像“!?”这样的自定义运算符('??'的否定)而不是写长表达式:
int? value = 1;
var newValue = value != null ? 5 : (int?)null;
我想拥有:
var newValue = value !? 5;
谢谢!
【问题讨论】:
-
value !? 5与value ?? 5有何不同?因为,newValue = value != null ? 5 : (int?)null;与newValue = value == null ? (int?)null : 5;相同
标签: c# .net new-operator