Tsallaka zuwa abun ciki
Justice Tech School

Nullable Types

Add ? to let a value type hold null. Use ?? for defaults and ?. for safe access.

Example
int? n = null;
string? s = null;
Console.WriteLine(n ?? -1);
Console.WriteLine(s?.Length ?? 0);
n ??= 5;
Console.WriteLine(n);

Exercise

Default value.

n  0

Quiz Test

What does int? allow?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.