Code Inspection: 'if' statement can be re-written as '??' expression
If you want to assign a value, pass an argument, or return from a method based on the nullability of an identifier, the clearest syntax you can use in these cases is the ?? (null-coalescing) operator.
Therefore, whenever ReSharper encounters an
if operator in the above-mentioned contexts, it suggests simplifying the expressions using the
Here is an example of a quick-fix suggested by this inspection:
After the quick-fix
Speaking about performance of both operators, there is no observable difference. Actually, the
?? is even a tiny bit faster.