为什么我不能在Descandants上调用FirstOrDefault("XName")

Mam*_*One 2 .net xml linq linq-to-xml c#-4.0

为什么我不能调用FirstOrDefault()这个XML,而我还有其他可用XDocument的地方FirstOrDefault()

        var actual = new XDocument(
            new XComment("This is a comment"),
            new XElement("Root",
                         new XElement("Child1", "data1"),
                         new XElement("Child2", "data2")
                ));

        actual.Descendants("Child1"). <- FirstOrDefault does not show up.
Run Code Online (Sandbox Code Playgroud)

Ser*_*lov 5

您应该System.Linqcs文件的顶部包含命名空间.
如果您正在使用ReSharper,请ctrl+alt+space在键入后尝试按下.并查找FirstOrDefault.R#有助于管理命名空间.