Buy Me a Coffee

Buy Me a Coffee!

Friday, November 16, 2018

Testing new syntax

A colleague used some syntax that I hadn't seen before so I thought it would be worth testing in isolation.  The notation is an extension of the ternary conditional operator known as the null-conditional operator that was added as part of C# 6.0 in 2016.  I believe I need to up my C# game.  Anyway, here is the sample program I built:

which outputs:
=>
=>Test2
We build our code using the null-conditional operator to avoid having to build out the more common tertiary version of the same code: