Questions tagged [coalescing]

49 questions
-1
votes
1 answer

PHP return in combination with null coalescing operator

I wonder if it is possible to exit a function e.g. by return in the second statement of a null coalescing operator in PHP. I want to use this to check some POST data in a function and exit the function if a POST var is not set. This would be clean…
-1
votes
4 answers

?? Operator (C#) for double returns incorrect result

Using C#, any idea why the following method returns 57.999999999999993 (instead of 58)? double Test_Null_Coalescing_Operator() { double? x = 0.58; return ((x ?? 0) * 100); } //returns 57.999999999999993 (instead of 58)
Samad
  • 1
-1
votes
1 answer

Add string to array if condition found using coalesce operator

I know I can test the condition and run the code like this: if (scrapedElement.Contains(".html") string [] Test = new string[] { scrapedElement, string.empty } else string [] Test = new string[] { scrapedElement } However, I want to do…
djblois
  • 963
  • 1
  • 17
  • 52
-1
votes
2 answers

In PHP 7 how would I convert this essential ternary function for my website to coalesce?

On my website ternary operators are used all over and I'm considering trying to update them to coalesce. This is just one example and I was hoping to get tips/suggestions on making the transition. The thing with coalesce is that it sends the first…
1 2 3
4