Skip to content

C# Feature - Null-conditional assignment

Null-conditional assignment allows the null-conditional operators ?. and ?[] to appear on the left-hand side of an assignment or compound assignment.

This feature was introduced in C# 14. The official Microsoft Learn page for C# 14 is dated November 18, 2025 and states that C# 14 ships with .NET 10 and Visual Studio 2026.

Before C# 14, code had to null-check a receiver explicitly before assigning through it. The new syntax removes that boilerplate while preserving short-circuit behavior.

if (customer is not null)
{
customer.Order = GetCurrentOrder();
}
customer?.Order = GetCurrentOrder();
cart?.Items[0] = replacementItem;
stats?["errors"] += 1;
  • The right-hand side is evaluated only when the receiver is not null.
  • Compound assignment operators such as += are supported.
  • Increment and decrement operators (++ and --) are not allowed in this form.
  • This syntax silently does nothing when the receiver is null, so do not use it when failure should be explicit.
  • It improves brevity, but not every null-handling branch should be collapsed into one line.