【发布时间】:2010-10-10 02:29:52
【问题描述】:
可能的重复:
Deep Null checking, is there a better way?
C# elegant way to check if a property's property is null
我必须像这样在深层对象模型中进行查找:
p.OrganisationalUnit.Parent.Head.CurrentAllocation.Person;
如果任何一个链为空(组织单元、父级、头部等),是否有评估这个并返回空,而不必做一个
if (p.org == null && p.org.Parent == null && p.org.Parent.Head . . .
【问题讨论】:
-
尽量避免这种查找;详情请看我下面的回答。