121
Elvis
(feddit.it)
Post funny things about programming here! (Or just rant about your favourite programming language.)
Because it's not one. Ternary operator is A ? B : C, Elvis operator is A ?: B. The same two characters are involved, but both the syntax and effect is different.
The second one isn't valid syntax in any programming language I'm familiar with. What does it do?
It's a shorthand for writing this:
This is equivalent:
Huh. Neat feature. That's in C# I assume?
It's in Kotlin and some other languages. C# has it but there it's actually
A ?? B
.