我正在学习 LINQ to XML,需要找到具有特定属性的元素的存在。目前我正在使用:
XElement groupCollectionXml = XElement.Parse(groupCollection.Xml);
IEnumerable<XElement> groupFind =
from vw in groupCollectionXml.Elements("Group")
where (string) vw.Attribute("Name") == groupName
select vw;
if (groupFind.Count() == 0)
return false;
else
return true;
我知道有一种更简洁的方法可以做到这一点,可能使用 Any(),但我不确定如何重写查询以使用它。有人有什么好的建议吗?谢谢。