0
public mainForm()
{
InitializeComponent();
}
string[,] summary = new string[10, 4];
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void calculateButton_Click(object sender, EventArgs e)
{
decimal monthlyInvestment =
Convert.ToDecimal (monthlyInvestmentTextBox.Text);
decimal yearlyInterestRate =
Convert.ToDecimal (interestRateTextBox.Text);
int years =
Convert.ToInt32(yearsTextBox.Text);
int months = years * 12;
decimal monthlyInterestRate = yearlyInterestRate/12/100;
decimal futureValue = 0;
for (int i = 0; i < months; i++)
{
futureValue = (futureValue + monthlyInvestment)
* (1 + monthlyInterestRate);
}
futureValueTextBox.Text = futureValue.ToString("c");
monthlyInvestmentTextBox.Focus();
}
該程序根據費率和年數計算投資的未來值。一旦用戶點擊計算,我希望程序以10x4的數組形式存儲多達10次計算。 4是投資,利率,年份和未來價值。點擊退出按鈕後,我想要一個消息框顯示10個以前的計算。我會如何去做這件事?謝謝。使用矩形陣列存儲值
不要使用矩形數組,爲投資,費率,年數和未來價值的屬性創建一個'FutureInvestments'類。然後,如果您需要存儲其中的10個,請使用「List」 –