Another way of describing '>=' is: Not Less Than. No mention of equals. As soon as one of the operands in a non-equality test is Null, the result is unknown as well (is null). However if you want to know if both operands are Null, then Null == Null is a reasonable test (should result in true). Getting rid of the inequality part of the operator makes all the difference.
The following code example from http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx#sectionToggle4 summarizes how C# treats Null:
int? num1 = 10;
int? num2 = null;
if (num1 >= num2)
{
Console.WriteLine("num1 is greater than or equal to num2");
}
else
{
// This clause is selected, but num1 is not less than num2.
Console.WriteLine("num1 >= num2 returned false (but num1 < num2 also is false)");
}
if (num1 < num2)
{
Console.WriteLine("num1 is less than num2");
}
else
{
// The else clause is selected again, but num1 is not greater than
// or equal to num2.
Console.WriteLine("num1 < num2 returned false (but num1 >= num2 also is false)");
}
if (num1 != num2)
{
// This comparison is true, num1 and num2 are not equal.
Console.WriteLine("Finally, num1 != num2 returns true!");
}
// 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 returned false (but num1 < num2 also is false)
* num1 < num2 returned false (but num1 >= num2 also is false)
* Finally, num1 != num2 returns true!
* num1 == num2 returns true when the value of each is null
*/
int?
), then their value is known.null
. – WellmanneredNull
) but the real problem domain entity/value that the variable is there to represent is Not known.. – Quodlibetval == null
. If C# had added a separate keyword for null-checking the way SQL does it, then that would not be the case. – Tackettnull
in C#. It's use for nullable types is identical to the use and meaning ofnull
in SQL, and should have been treated that way. It's other use, (equivilent to a null pointer in C/C++) means that a reference variable is unassigned. Pity these two very different situations are not represented with a different keyword. The use of same keyword for both does engender some confusion. – Quodlibet