DEV Community

Ramkumar Radhakrishnan
Ramkumar Radhakrishnan

Posted on

C# 14 Fav Feature

Recently I had a chance in reading C# 14 new features. You can refer here -

If you dont find a time, and you want to pick one update which can save your coding a much extend. Here it is.

Null-conditional assignment

Previously, we had to check the not null before assignment as

if (customer is not null)
{
customer.Order = GetCurrentOrder();
}

Now it can be changed to

customer?.Order = GetCurrentOrder();

The right side of the = operator is evaluated only when the left side isn't null. If customer is null, the code doesn't call GetCurrentOrder.

Top comments (0)