C# Null Propagation

It makes things so simple, I really wish other languages had it. Today in five or six places I wrote something like

_innerObject?.Dispose();

instead of

if (_innerObject != null) _innerObject.Dispose();

Long live DRY principle! Of course, our friend Juan Gandhi will probably say it is a Maybe monad (hey, how come in this day and age Chrome spell checker does not know the word “monad”?!). Anyhow, I wish this kind of shortcut were present in JavaScript. I really miss it. The proposal is already there, but I am not sure how long it will take it to get to the standard, if at all.

3 Comments


    1. This is entirely possible. I wish more languages adopted this idea.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *