I have code that extracts data out of an XML file. I want to find the average / mean value for each of the extracted values (XMax, XMin, YMax, YMin, ZMax, ZMin)
Here is how I extracted the six values:
var query = from file in fileEntries
let doc = XDocument.Load(file)
let x = doc.Descendants("XAxisCalib").Single()
let y = doc.Descendants("YAxisCalib").Single()
let z = doc.Descendants("ZAxisCalib").Single()
select new
{
XMax = x.Element("Max").Value,
XMin = x.Element("Min").Value,
YMax = y.Element("Max").Value,
YMin = y.Element("Min").Value,
ZMax = z.Element("Max").Value,
ZMin = z.Element("Min").Value
};
Am I on the right track with this average for XMax:
var Average1 =
from a in query
select new
{ AvgMaxX = a.Average(a => a.XMax) };
EDIT: To convert the strings to doubles or decimals or whatever:
But I would actually do it in the select: