The Null Reference

So as not to complicate the discussion prematurely, I’ve not yet introduced a special citizen in the world of reference types: null. Recall that reference types refer to some data that lives somewhere in memory. Multiple variables of that reference type can refer to the same data simultaneously, causing aliasing. However, it’s equally valid for a variable of a reference type to refer to nothing. This is known as the null reference. Think of it as a special “value” every reference type has available, readily provided by the runtime. In C#, the null literal can be used to write down a null reference. For example:

string name = null;

Notice the null literal by and in itself doesn’t have a type. More specifically, it’s one of ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.