【发布时间】:2014-01-07 13:55:50
【问题描述】:
此方法是减少 textBox1 的值,以减少插入到 textBox2 中的数量。如果 textBox1 中没有足够的“钱”,则应从 textBox3 中取出多余的金额。最后,方法应该将文本框更新为新值,但只有 textBox2 被清除,而 textBox1 和 textBox3 保持不变。谁能告诉我为什么textBox1.text = Account.toString() 没有将文本框值分配给变量Account 的值,而textBox3.text = Savings.toString() 没有将文本框值分配给变量Savings 的值?
public void Debit(decimal amount)
{
decimal Account = Convert.ToDecimal(textBox1.Text);
decimal Savings = Convert.ToDecimal(textBox3.Text);
if ((Account + Savings) < amount)
if (Overdrawn != null)
Owerdrawn(this, new OverdrawnEventArgs (Account, amount));
else if (Account >= amount)
Account -= amount;
else {
amount -= Account;
Account = 0m;
Savings -= amount;
}
textBox1.Text = Account.ToString();
textBox2.Clear();
textBox3.Text = Savings.ToString();
}
【问题讨论】:
-
你试过
textBox1.Text = String.Format("N0", Account)吗? -
请养成描述性命名文本框的习惯。它将防止未来的程序员在查看您的代码时过早秃顶!
-
谢谢!它就是这样工作的。但仍然无法弄清楚为什么使用 toString() 不起作用:/ @MichaelMcGriff 对不起,我会记住这一点