3 ms·
Yeah, I thought this was going to involve the ternary operator. TIL about trigraphs.
by teawrecks 4y ago
Yeah, I thought this was going to involve the ternary operator. TIL about trigraphs.
- sargstuff 4y agostill can, just have to add precidence changing characters ( )
- LorenPechtel 4y agoYeah, C# has some shortcuts these days of the form x <symbol>= y that compile as x = x <symbol> y. They are an actual advantage as x only needs to be stated once and it is absolutely clear that is assignment into the value--more information readily communicated with fewer characters. It also has the null coalescing operator ??. Put those together and you can have x ??= y (if (x = null) x = y;)--useful for lazy initialization and it can be returned, making lazy initialization getters much clearer. This looked awfully similar, I was trying to figure out how you could negate null coalescing.
- pjmlp 4y agoThese days, like since C# 1.0.
- tuukkah 4y agoIt's interesting to see the history of any given piece of syntax. This specific one is called augmented assignment or compound assignment: https://en.wikipedia.org/wiki/Augmented_assignment https://en.wikipedia.org/wiki/Augmented_assignment +:= in Algol68 =+ in B += in C