?? Coalesce for empty string?

Something I find myself doing more and more is checking a string for empty (as in “” or null) and a conditional operator. A current example: s.SiteNumber.IsNullOrEmpty() ? “No Number” : s.SiteNumber; This is just an extension method, it’s equivalent to: string.IsNullOrEmpty(s.SiteNumber) ? “No Number” : s.SiteNumber; Since it’s empty and not null, ?? won’t … Read more

is there a Java equivalent to null coalescing operator (??) in C#? [duplicate]

This question already has answers here: How to get the first non-null value in Java? (13 answers) Closed 4 years ago. The community reviewed whether to reopen this question 5 months ago and left it closed: Original close reason(s) were not resolved Is it possible to do something similar to the following code in Java … Read more

PHP ternary operator vs null coalescing operator

Can someone explain the differences between ternary operator shorthand (?:) and null coalescing operator (??) in PHP? When do they behave differently and when in the same way (if that even happens)? $a ?: $b VS. $a ?? $b 14 s 14 When your first argument is null, they’re basically the same except that the … Read more

Is there a “null coalescing” operator in JavaScript?

Is there a null coalescing operator in Javascript? For example, in C#, I can do this: String someString = null; var whatIWant = someString ?? “Cookies!”; The best approximation I can figure out for Javascript is using the conditional operator: var someString = null; var whatIWant = someString ? someString : ‘Cookies!’; Which is sorta … Read more

What do two question marks together mean in C#?

Ran across this line of code: FormsAuth = formsAuth ?? new FormsAuthenticationWrapper(); What do the two question marks mean, is it some kind of ternary operator? It’s hard to look up in Google. 1 19 It’s the null coalescing operator, and quite like the ternary (immediate-if) operator. See also ?? Operator – MSDN. FormsAuth = … Read more