Is ?? necessary, or should you just use the ternary operator (that most are familiar with)
Actually, my experience is that all too few people are familiar with the ternary operator (or more correctly, the conditional operator; ?:
is "ternary" in the same sense that ||
is binary or +
is either unary or binary; it does however happen to be the only ternary operator in many languages), so at least in that limited sample, your statement fails right there.
Also, as mentioned before, there is one major situation when the null coalescing operator is very useful, and that is whenever the expression to be evaluated has any side effects at all. In that case, you cannot use the conditional operator without either (a) introducing a temporary variable, or (b) changing the actual logic of the application. (b) is clearly not appropriate in any circumstances, and while it's a personal preference, I don't like cluttering up the declaration scope with lots of extraneous, even if short-lived, variables, so (a) is out too in that particular scenario.
Of course, if you need to do multiple checks on the result, the conditional operator, or a set of if
blocks, are probably the tool for the job. But for simple "if this is null, use that, otherwise use it", the null coalescing operator ??
is perfect.