C# in Depth

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

Magic value traps

Chapter 4: Saying nothing with nullable types: 4.1.2

Created: 5/13/2008
Last updated: 5/13/2008

Joe Albahari pointed out that another problem with magic values is that it's easy to forget to check for them:

There's nothing to stop you from accidentially treating it like a real value, and performing arithmetic on it, causing an error, potentially way down the line. If you make the same mistake with a nullable type, you'll get an exception thrown right away. This is probably the most convincing argument for the usefulness of nullable types over magic values.