public class SumsThirdDegree : ThirdDegree
{
public SumsThirdDegree(List<ThirdDegree> allValues)
{
this.SumAllValues(allValues);
}
private void SumAllValues(List<ThirdDegree> allValues)
{
this.X = allValues.Sum(x => x.X);
this.Y = allValues.Sum(x => x.Y);
this.XY = allValues.Sum(x => x.XY);
this.XSecY = allValues.Sum(x => x.XSecY);
this.XThirdY = allValues.Sum(x => x.XThirdY);
this.XSecond = allValues.Sum(x => x.XSecond);
this.XThird = allValues.Sum(x => x.XThird);
this.XFourth = allValues.Sum(x => x.XFourth);
this.XFifth = allValues.Sum(x => x.XFifth);
this.XSixth = allValues.Sum(x => x.XSixth);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
var allProperties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var prop in allProperties)
{
sb.AppendLine($"Sum of {prop.Name} is: {prop.GetValue()}");
}
return sb.ToString();
}
}
It is about ToString() method because I want to dynamically get all props names and their values. I don't know if it is possible to do that inside of the current class.