我一直在尝试通过创建一个允许用户添加当前或储蓄帐户的基本银行应用程序来学习一些C#。如果它是一个经常账户,那么它将起始余额乘以0.2,如果它是一个储蓄,那么它乘以0.6。当他们添加一个帐户时,应用程序应该将其保存到列表中,并最终显示所有帐户名称。到目前为止,我有一个允许用户添加名为AddAccount.cs的帐户的表单。然后,我有一个Account.cs应该设置帐户,然后AccountList.cs将其添加到列表中。C#检索数据并将其存储在列表中
我需要什么帮助:
- 我如何通过新的帐户信息并设置他们在Account.cs?
- 然后如何将账户添加到列表中并显示账户的名称?
Account.cs:
abstract class Account
{
public string accName, accId, accType;
public double balance;
public void setValues(string name, string id, double bal, string type)
{
this.accName = name;
this.accId = id;
this.balance = bal;
this.accType = type;
}
}
class CurrentAccount : Account
{
public double interst()
{
return balance * 0.2;
}
}
class SavingsAccount : Account
{
public double interst()
{
return balance * 0.6;
}
}
AddAccount.cs:
private void btn_AddAccount_Click(object sender, EventArgs e)
{
string name, id, type;
double balance;
name = input_AccountName.Text;
id = input_AccountNo.Text;
balance = Convert.ToDouble(input_StartBalance.Text);
if (radio_CurrentAccount.Checked)
{
type = "C";
}
else
{
type = "S";
}
//closes the form when clicked
this.Close();
}
AccountList.cs:
class AccountList
{
private List<Account> accountlst;
public List<Account> AccountLst
{
get { return accountlst; }
}
}
如果我完全错了,请让我知道。即使最细微的帮助,将不胜感激。
在AddAccount.cs您提取的输入,并设置局部变量。当代码从添加退出点击你失去了一切,你需要类型账户的一类级别的变量,并设置其属性,那么你这个帐户添加到列表中 – Steve