System.Xml.Linq.XDocument类是否实现了IEnumerable <T>?

dev*_*747 1 c# linq

我知道你不能在没有实现的对象上运行LINQ语句IEnumerable<T>.我也知道你可以针对XDocument类的实例运行LINQ语句.

比如我能做到的

    XDocument people = XDocument.Load(@"People.xml");

    var legalDrinkers = from x in people.Descendants("person")
                        where int.Parse(x.Attribute("Age").ToString()) > 21
                        select x;
Run Code Online (Sandbox Code Playgroud)

但是当我查看XDocument的元数据和其继承层次结构中的所有上游类时,我看不到IEnumerable<Xdocument>实现的位置.我在这里错过了什么?

Ree*_*sey 5

您不直接从XDocument使用LINQ,而是使用其中的方法,例如XDocument.DescendantsElements实现所需接口的方法.