O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lifted Operators

For nullable value types, the relational operators are also lifted. Comparison of a non-null value to null always results in false, except when inequality is checked:

int? a = 5;int? b = null;bool gt = a >  b; // falsebool le = a <= b; // falsebool eq = a == b; // falsebool ne = a != b; // true

Nullable logic can be surprising. For example, if you thought the result of >= and < would always be exact opposites when applied to the same operands, you can clearly see this doesn’t hold any longer when null is in play.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required