Multiple descendants types linq

2019-07-06 13:49发布

I sometimes do this:

XElement.Descendants("mynodename");

is there a way to do something like this"

XElement.Descendants("mynodename or myothernodename");

2条回答
一纸荒年 Trace。
2楼-- · 2019-07-06 14:12

Or,

XElement.Descendants("mynodename")
  .Union(XElement.Descendants("myothernodename"));

Which would sort them by type, then in order of appearance...

查看更多
淡お忘
3楼-- · 2019-07-06 14:31

Not in one method call - but you can use:

element.Descendants()
       .Where(x => x.Name.LocalName == "mynodename" 
                   || x.Name.LocalName == "myothernodename")
查看更多
登录 后发表回答