XPathSelectElement vs Descendants
c#, linq-to-xml, xml
Solution
Note that this
var x = document.Elements("actors").Elements("actor").FirstOrDefault();
is the equivalent of your first statement.
There will be a performance difference, because the methods are doing very different things under the hood. However, optimising purely in-memory operations is a bit pointless unless you are dealing with a large data set. If you are dealing with a large data set, then you should measure the performance of both alternatives rather than trying to predict which one will run faster.
Problem
I was wondering if there are any performance differences when using simple queries as: ``` var x = document.XPathSelectElement("actors/actor") vs var x = document.Descendants("actors").Descendants("actor") ```