In C#, is there a clean way of checking for multiple levels of null references

Viewed 9398

For example, if I want to call the following: 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?

9 Answers
if (person?.Head?.Nose != null) person.Head.Nose.Sniff();   
Related