В C # существует чистый способ проверки нескольких уровней нулевых ссылок

Например, если я хочу вызвать следующие: person.Head.Nose.Sniff () then, if I want to be safe, I have to do the following:

if(person != null)
    if(person.Head != null)
        if(person.Head.Nose != null)
            person.Head.Nose.Sniff();

Is there any easier way of formulating this expression?

18
задан Lernkurve 10 July 2016 в 20:19
поделиться