C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Equality of nulls

Chapter 4: Saying nothing with nullable types: 4.2.3

Created: 2/22/2008
Last updated: 2/22/2008

As the book mentions, all the various operators are language-specific. Equality is a particularly good example. In VB, x=y (as an equality comparison, not an assignment) has a nullable result when x or y are nullable. If both sides are null values, then the result is null.

The language designers decided that was one step too far for C#. Which is the best approach? It's very hard to say. I'm sure that in some scenarios the C# way is clearer, and in others the VB way is clearer.

It pains me to cede the point, but in this particular case I think that VB has more purity and integrity than C#. Just don't remind me about it too often :)