adsense

Sunday, May 4, 2025

C# 14 New feature for Null conditional assignment

The preview of .NET 10 and the upcoming C# version introduces a potential new feature: null-conditional assignment. This aims to simplify code where you assign a value to a property only if the object isn't null.

Currently, you'd write:

if (classObj is not null)

{

  classObj .Property = 100;

}

With the new feature, this can be shortened to:

classObj ?.Property = 100;

This makes the code more concise and readable when dealing with potentially null objects.


Cheers,

Samitha

No comments:

Post a Comment