I am having trouble with the OrderByDescending. It does not sort it correctly. I have an XML file that looks like this:
<player id="3">
<name>David, Backham</name>
<goals>155</goals>
</player>
I am trying to display 3 players with the highest amount of goals.
XDocument doc = XDocument.Load("players.xml");
/// .OrderByDescending(r => r.Attribute("goals"))
var players = from r in doc.Descendants("player").OrderByDescending(r => r.Value)
select new
{
Name = r.Element("name").Value + " ",
Goal = r.Element("goals").Value + " ",
};
foreach (var r in players)
{
Console.WriteLine(r.Name + r.Goal);
}