Important C# Topics

Nullable Reference Types

Make possible null values visible to the compiler.

Introduction

Nullable annotations help prevent NullReferenceException by distinguishing optional references from required ones.

string? permits null. The null-coalescing operator supplies a safe fallback before Length is accessed.

Runnable C# example

C#
Run code →
Program.cs
using System;

class Program
{
    static void Main()
    {
        string? nickname = null;
        string displayName = nickname ?? "Anonymous";
        Console.WriteLine($"{displayName} ({displayName.Length})");
    }
}
Result of running the code
Anonymous (9)

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.