Why can't I call FirstOrDefault()
on this XML, whereas I have other XDocument
s where FirstOrDefault()
is available?
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.
You should include System.Linq
namespace in the top of your cs file.
If you're using ReSharper, try push ctrl+alt+space
after typing .
and look for FirstOrDefault
. R# helps to manage namespaces.
It works for me:
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();
make sure you have using System.Linq in your using directives.
精彩评论