Caffeinated Coder
Book an appointment
Lesson 10 · Objects

Null and nullable types

null means "no object". Follow a seven-line program that keeps three variables honest: string? marks a reference that may be null, int? (Nullable<int>) gives a value type a HasValue flag, ?. and ?? turn a missing value into a safe default, ??= fills in a null, and the compiler, Roslyn, tracks which variables may be null so you fix a NullReferenceException before it ever happens. The program prints 33.

12 min9 steps5 questionsIntermediate
Fig 10 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.