【发布时间】:2014-07-04 11:24:51
【问题描述】:
在 C# 中是
x = y ?? null;
总是等价于
x = y;
如果 x 和 y 都是可空类型?
我想不出为什么需要第一行代码而不是第二行。
【问题讨论】:
-
我正在使用 null-coalescing 运算符重构 if 语句,并注意到 smart sense 和 refactor 对此没有任何提示。我很好奇。
标签: c# refactoring simplify null-coalescing-operator