O'Reilly logo

Pro C# 2010 and the .NET 4 Platform, Fifth Edition by Andrew Troelsen

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

4.6. Understanding C# Nullable Types

To wrap up this chapter, let's examine the role of nullable data type using a final Console Application named NullableTypes. As you know, CLR data types have a fixed range and are represented as a type in the System namespace. For example, the System.Boolean data type can be assigned a value from the set {true,false}. Now, recall that all of the numerical data types (as well as the Boolean data type) are value types. Value types can never be assigned the value of null, as that is used to establish an empty object reference:

static void Main(string[] args) { // Compiler errors! // Value types cannot be set to null! bool myBool = null; int myInt = null; // OK! Strings are reference types. string myString = ...

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