当我在文本框中输入时,我希望它添加数字,而不是如果我输入(例如)12,然后再次单击存款,它只显示 12。我认为这是因为它似乎认为那是它的 0 加 12每次。某些东西似乎没有正确实例化。我认为。谁能指出我做错了什么?
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_deposit_Click(object sender, EventArgs e)
{
double input;
input = double.Parse((putin.Text));
BankAccount a = new BankAccount(input);
aMtBox.Text = a.AccountBalance.ToString();
}
}
public class BankAccount
{
private double num1;
private double accountBalance;
public BankAccount(double input)
{
num1 = input;
Deposit();
}
public double Num1
{
set {num1 = value;}
get {return num1;}}
public double AccountBalance
{
get {return accountBalance;}
set {accountBalance = value;}}
public void Deposit()
{
accountBalance = accountBalance + num1;
}
}
}