c# - How does comparison operator works with null int? -
i starting learn nullable types , ran following behavior.
while trying nullable int, see comparison operator gives me unexpected result. example, in code below, output "both , 1 equal". note, not print "null" well.
int? = null; int? b = 1; if (a < b) console.writeline("{0} bigger {1}", b, a); else if (a > b) console.writeline("{0} bigger {1}", a, b); else console.writeline("both {0} , {1} equal", a, b);
i hoping non-negative integer greater null, missing here?
according msdn - it's down page in "operators" section:
when perform comparisons nullable types, if value of 1 of nullable types
null
, other not, comparisons evaluatefalse
except!=
so both a > b
, a < b
evaluate false
since a
null...
Comments
Post a Comment