var runnerElement = xDox.Descendants("User")
.SingleOrDefault(u => u.Element("Name").Value == "David");
if (runnerElement != null)
{
var result = runnerElement.Descendants("Runners")
.Select(a => new
{
Date = DateTime.Parse(a.Element("Date").Value),
MyLength = int.Parse(a.Element("Length").Value)
City = a.Element("City").Value,
})
.Where(a => a.Date >= DateTime.Parse("3/29/2012")
&& a.Date <= DateTime.Parse("8/29/2012"))
.GroupBy(a => a.City)
.Select(g => new {City = g.Key, Avg = g.Average(x => x.MyLength)});
}
您将如何遍历这些数据,以便它可以给我这样的输出
User:David
Date:3/29/2012 to 8/29/2012
Average Distance in Paris : //Data
Average Distance in Madrid: //Data
我尝试进一步澄清我的代码..