null coalescing
The ?? operator returns the left operand if not null, otherwise the right. ??= assigns only if the variable is null.
Syntax
csharp
result = value ?? fallback;
variable ??= defaultValue;Example
csharp
string name = user.Name ?? "Anonymous";
int count = GetCount() ?? 0;
// Null-conditional combined:
string city = user?.Address?.City ?? "Unknown";
// Null coalescing assignment:
_cache ??= new Dictionary<string, object>();