Advertisement
Intermediate C#, Nullable Reference Types

What is the difference between ?., ?? and ??=?

Short answer

?. is null-conditional access (returns null instead of throwing); ?? is null-coalescing (fallback value); ??= assigns only if the target is null.

Save C# mock interview
Advertisement
AModel answer
?. is null-conditional access (returns null instead of throwing); ?? is null-coalescing (fallback value); ??= assigns only if the target is null.
int len = name?.Length ?? 0;
cache ??= new();
Real-world example
Safely reading a nested property and defaulting when any link is null.