logoalt Hacker News

Metasyntactictoday at 9:12 AM1 replyview on HN

Hi there! One of the lang designers here.

That's been part and parcel for C# for over 10 years at this point. When we added `?.` originally, it was its nature that it would not execute code that was now unnecessary due to the receiver being null. For example:

    Settings?.SetRetryPolicy(new ExponentialBackoffRetryPolicy());
This would already not run anything on the RHS of the `?.` if `Settings` was null.

So this feature behaves consistently with how the language has always treated this space. Except now it doesn't have an artificial limitation on which 'expression' level it stops at.


Replies

SideburnsOfDoomtoday at 11:43 AM

I get that the language syntax is now (slightly) more regular.

But also, reading the code will mean keeping track of (slightly) more possible outcomes.

show 1 reply