[Solved] Use of null-coalescing operator and difference b/w ?? and ??= operators [duplicate]


when to use ??= operator?

From MSDN:

The null-coalescing assignment operator ??= assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null.

For example,

int? a = null;
...
a ??= 5;   //Here a is null, so assign 5 to a
int b = a ?? 0;

a ??= 5;

can be written like,

a = a ?? 5;

0

solved Use of null-coalescing operator and difference b/w ?? and ??= operators [duplicate]