Boxing and unboxing nullable values - CSharp Language Basics

CSharp examples for Language Basics:Nullable

Introduction

When T? is boxed, the boxed value on the heap contains T, not T?.

C# also permits the unboxing of nullable types with the as operator.

The result will be null if the cast fails:

object o = "string";
int? x = o as int?;
Console.WriteLine (x.HasValue);   // False

Related Tutorials