我知道你不能在沒有實現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