var g1 = parent?.child?.child?.child;
if (g1 != null) // TODO
Wow! This is the equivalent of testing every single level, but in a single line of code. The “?.” operator is basically saying:
if the object to the left is not null, then fetch what is to the right, otherwise return null and halt the access chain.
No comments:
Post a Comment