【发布时间】:2017-02-13 21:34:00
【问题描述】:
C# 5.0 规范见第 7.1.3 章
https://msdn.microsoft.com/en-us/library/ms228593.aspx
如果一个或两个操作数是
null,则提升的运算符产生值false。
然而测试和这个 MSDN 链接
http://msdn.microsoft.com/en-us/library/2cf62fcy(v=vs.100).aspx
int? num1 = 10;
int? num2 = null;
// Change the value of num1, so that both num1 and num2 are null.
num1 = null;
if (num1 == num2)
{
// The equality comparison returns true when both operands are null.
Console.WriteLine("num1 == num2 returns true when the value of each is null");
}
/* Output:
* num1 == num2 returns true when the value of each is null
*/
表明比较两个都为null 的可为空值返回true。
这是有道理的,但它与规范中的句子相矛盾,不是吗?
【问题讨论】:
-
我在第 7.3.7 章中找到了这个。请注意,这是针对
binary operators。下一节将讨论equality operators,其中包括==。
标签: c# nullable lifted-operators