when to use ??=
operator?
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 tonull
.
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]