C# Feature - Null-conditional assignment
Null-conditional assignment
Section titled “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.
Introduced In
Section titled “Introduced In”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.
Why This Feature Exists
Section titled “Why This Feature Exists”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.
Before
Section titled “Before”if (customer is not null){ customer.Order = GetCurrentOrder();}customer?.Order = GetCurrentOrder();Practical Example
Section titled “Practical Example”cart?.Items[0] = replacementItem;stats?["errors"] += 1;Rules and Behavior
Section titled “Rules and Behavior”- 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.
Common Pitfalls
Section titled “Common Pitfalls”- 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.