【发布时间】:2015-04-02 19:21:58
【问题描述】:
如何将这两个 linq 查询重写为一个? .AncestorsAndSelf 不支持 null 作为元素名称。
if (ancestorElementName == null)
{
ancestorElements =
currentElement
.AncestorsAndSelf()
.Select(
.
.
.
);
}
else
{
ancestorElements =
currentElement
.AncestorsAndSelf(ancestorElementName)
.Select(
.
.
.
);
}
【问题讨论】:
-
为了澄清你想在指定元素不为空时使用linq来选择它?
标签: c# linq linq-to-xml