【发布时间】:2014-03-05 08:44:51
【问题描述】:
我有一个列表,我想使用列表中创建的最新对象来计算下一个对象属性。我不确定如何编写循环来做到这一点。你能帮我解决这个问题吗?
public ActionResult ShowDetail(DateTime startdate, double PresentValue, double InterestRate, double FutureValue, int PaymentPeriods)
{
List<Calculation> cList = new List<Calculation>();
Calculation calc = new Calculation();
calc.Date = startdate.ToShortDateString();
calc.InvoiceAmount = 2000;
calc.InterestRate = InterestRate;
calc.InterestAmount = (PresentValue * InterestRate / 360 * 30);
calc.Amortization = (2000 - (PresentValue * InterestRate / 360 * 30));
calc.PresentValue = PresentValue;
cList.Add(calc);
for (int i = 0; i < PaymentPeriods; i++)
{
cList.Add(new Calculation()
{
var calcBefore = cList.GetLastObject //Some how I want to take the object before the one i want to create
cList.Add(new Calculation()
{
Date = calcBefore.Date.Add(1).Month() //something like this
InvoiceAmount = calcBefore.InvoiceAmount
InterestRate = calcBefore.InterestRate
InterestAmount = (calcBefore.PresentValue * InterestRate / 360 * 30) //I want to take the presentvalue from the object before in the List and use that to calculate the the next InterestAmount
//And so on
}
});
}
return PartialView("ShowDetail", cList);
}
计算:
public partial class Calculation
{
public string Date { get; set; }
public double InvoiceAmount { get; set; }
public double InterestRate { get; set; }
public double InterestAmount { get; set; }
public double Amortization { get; set; }
public double PresentValue { get; set; }
}
【问题讨论】:
-
“我不确定如何编写循环来做到这一点。” ?将编辑文本,以便您更轻松地查看它