Multiple descendants types linq

久未见 提交于 2020-01-04 02:07:08

问题


I sometimes do this:

XElement.Descendants("mynodename");

is there a way to do something like this"

XElement.Descendants("mynodename or myothernodename");

回答1:


Not in one method call - but you can use:

element.Descendants()
       .Where(x => x.Name.LocalName == "mynodename" 
                   || x.Name.LocalName == "myothernodename")



回答2:


Or,

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

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



来源:https://stackoverflow.com/questions/2059488/multiple-descendants-types-linq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!