---
title: "C# 14: Null-conditional assignment"
description: "The preview 1 of dotnet 10, and therefore the next iteration of the C# language, is right in front of our doorsteps. So let's have a look at one of the first potential additions to the language: **Null-conditional assignment**."
updated: 2025-02-24
tags: ["C# 14", "C#"]
canonical: "https://steven-giesel.com/blogPost/b6d22649-7fba-488b-b252-31efdb3686c5/c-14-nullconditional-assignment"
---

# C# 14: Null-conditional assignment

The preview 1 of dotnet 10 and therefore the next iteration of the C# language is right in front of our doorsteps. So let's have a look at one of the first potential additions to the language: **Null-conditional assignment**.

The basic problem it tries to solve is something like this: Imagine you have a variable which might be `null`. If it isn't you want to assign a property. The way to do it now is:
```csharp
MyObject? myObj = CallThatMightCreateMyObject();

if (myObj is not null)
{
  myObj.Property = 100;
}
```

The [proposal](https://github.com/dotnet/csharplang/issues/8677) tries to tackle exactly this - the code above can be shortened to:

```csharp
MyObject? myObj = CallThatMightCreateMyObject();
myObj?.Property = 100;
```

So if `myObj is not null` the assignment will be called, otherwise not. Basically, a fancy compiler sugar for the same code as above.

To be absolutely clear, you can also do those "beautiful" assignments:
```csharp
MyDeeplyNestedObj? m = FromSomewhere();
m?.A?.B?.C?.D = "Foo Bar";
```