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

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 ...

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