Programming foundations

Stage 1 · Lesson 7 of 9

null and nullable reference types

Your first language

A variable of a reference type can hold null, meaning "no object here". Calling a method on it throws NullReferenceException, the most common crash in C#. New projects turn on .

With them, string means "should never be " and string? means "might be null". The compiler then warns when you use a string? without checking it first. Take those warnings seriously.

The language gives you tools for this: if (name is null), the ?. as in order?.Customer, and the ?? as in name ?? "Guest", which supplies a fallback. Console.ReadLine() returns string?, which is why the compiler warns the first time you use its result. Fix the cause rather than silencing the warning with !.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • GuideFree
    Learn C#

    Microsoft · Beginner

    Official C# fundamentals tutorials that you run locally with the .NET SDK

  • PlatformFree
    freeCodeCamp

    freeCodeCamp · Beginner

    Free Foundational C# certification, built with Microsoft, with a graded exam at the end

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • Quick C# syntax lookups with a try-it editor; not a replacement for the course

Mark this stage as not done?