class Foo
{
public List<float> Data { get ; set ; } // list of numbers
private float Total { get ; set ; } // Contains sum of numbers in Data
// Constructors and other stuff.
}
My code that uses this class keeps modifying Data
so I want to see the relevant changes in Total
also.
I don't want to add function that recalculates Total
to the code that modifies Data
.
Example:
Foo f = new Foo(); // Total = 0
f.Data.Add(10); // Total = 10
f.Data.Add(30); // Total = 40
f[1] = 40; // Total = 50
// etc
So What is the solution to this problem ?