我知道你不能在没有实现IEnumerable<T>
的对象上运行LINQ语句。我也知道你可以针对XDocument类的一个实例运行LINQ语句。System.Xml.Linq.XDocument类是否实现IEnumerable <T>?
比如我可以做
XDocument people = XDocument.Load(@"People.xml");
var legalDrinkers = from x in people.Descendants("person")
where int.Parse(x.Attribute("Age").ToString()) > 21
select x;
但是,当我看的XDocument的元数据和所有上游在其继承层次的类,我看不到的地方IEnumerable<Xdocument>
实现。我在这里错过了什么?
请显示“可以针对XDocument实例运行LINQ语句”的示例。 – 2013-04-22 01:02:06
但是这个示例并不是针对'XDocument'实例(对Reed Copsey的答案+1),而是针对方法返回的节点集合... – 2013-04-22 01:09:28