的C#5.0规范中读取章节7.1.3比较两个空nullables
https://msdn.microsoft.com/en-us/library/ms228593.aspx
提升运算的结果为
false
如果一个或两个操作数null
。
但是测试也该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
2个空的值。
它是有道理的,但它与规范的句子相矛盾,不是吗?
我在章节7.3.7中找到了这个。注意这是针对'二元操作符'的。下一节将讨论'平等运算符',其中包括'=='。 – Gavin
[空条件运算符可能重复bool而不是bool?如预期般](http:// stackoverflow。COM /问题/ 37277102 /空条件运营商 - 测定到的BOOL不是对布尔 - 如预期) –