I'm new to C# and looking for a smart way to reduce redundancy in my code.
public double sumx()
{
double temp = 0;
foreach (var item in col)
{
temp= temp + item.x;
}
return temp;
}
public double sumy()
{
double temp = 0;
foreach (var item in col)
{
temp = temp + item.y;
}
return temp;
}
col is of type List< Point > and Point is a class by my own, which provides two properties (x and y) and an constructor Point(x,y).
I want now the sum of all x, respectively sum of all y.
I'm looking for a more generalized sum function, which maybe uses delegates or Lambda expressions. I have no Idea how to do this in a smart c# way.
Thanks in advance