DEV Community

Discussion on: Avoiding Nulls with Extension Methods

Collapse
 
peledzohar profile image
Zohar Peled • Edited

Of course, your trivial extension method can be simplified to a single line using the ?. operator - which of course comes from the same way of thinking - void operations on null references are no-ops...

Collapse
 
entomy profile image
Patrick Kelly

?. isn't a no-op. It's an expression which returns null. Now, you've got a null expression sitting there which either needs to be discarded in the case of an intended no-op, or downstream needs to put the default value rather than the method internalizing the default value.

Is this syntactic sugar for things that can already be done? Yes. But then every language construct is syntactic sugar for things that can already be done.