This is probably very simple, but my attempts (guided by Intellisense and MSDN) have all been off the mark.
If I have a class which contains 3 double, how can I get the average of a list of these?
class DataPoint
{
public int time;
public int X;
public int Y;
public int Z;
// Constructor omitted
}
class Main
{
List<DataPoint> points = new List<DataPoint>();
// Populate list
DataPoint averagePoint = points.Average(someMagicHere);
}
I want averagePoint to contain time, x, y & z values that are the average of these properties of the elements that make up the list. How do I do this? The bit I’m struggling with is (I think) someMagicHere, but I could be using completely the wrong approach to begin with.
1 Answer