Open In App

Null-Coalescing Assignment Operator in C# 8.0

C# 8.0 has introduced a new operator that is known as a Null-coalescing assignment operator(??=). This operator is used to assign the value of its right-hand operand to its left-hand operand, only if the value of the left-hand operand is null. If the left-hand operand evaluates to non-null, then this operator does not evaluate its right-hand operand.

Syntax:



p ??= q

Here, p is the left and q is the right operand of ??= operator. If the value of p is null, then ??= operator assigns the value of q in p. Or if the value of p is non-null, then it does not evaluate q.

Important Points:




Article Tags :
C#