Tsallaka zuwa abun ciki
Justice Tech School

C# Null Operators

?? gives a default when a value is null and ?. stops safely when the object is null. Nullable types are written with ?, such as int?.

Example
string? name = null;
Console.WriteLine(name?.Length ?? 0);
int? maybe = null;
Console.WriteLine(maybe.HasValue);
Console.WriteLine(maybe ?? -1);

Exercise

Default when null.

name  "unknown"

Quiz Test

What does ?. do?

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