Following scenario:
public class Data
{
public Data()
{
Details = new List<Details>();
}
public List<Details> Details {get; set;}
}
public class Details
{
public Details()
{
}
public decimal A {get; set;}
public decimal B {get, set;}
}
Later in the code:
Data dt = new Data();
Details det = new Details();
det.A = 2;
dt.Details.Add(det); // add X amount of details to the list
.........
Now the list will look like this:
Item 1: A = 2 , B = 0
Item 2: A = 2 , B = 0
Item 3: A = 2 , B = 0
Item 4: A = 2 , B = 0
.....
Item N: A = 2 , B = 0
How can I calculate the B property value like this:
Basically:
Item 1 A is the starting point and has whatever value ...
Item 1 B value will always be the same as Item 1 A
Item 2 A can be whatever
Item 2 B = Item 1 B + Item 2 A
Item 3 A can be whatever
Item 3 B = Item 2 B + Item 3 A
and so forth.
How can I iterate through the list and automatically calculate the B property value of the items?