我有两个帐户可以合并到一个新的支票帐户中。这应该创建具有 2 个余额总和的新支票帐户。我有一个代码:
public void ConsolidateAccounts(int accountNumber1, int accountNumber2)
{
if (accountNumber1 == accountNumber2)
{
throw new InvalidOperationException("Same accounts can not be consolidated");
}
else
{
int newAccountNumber = 0;
var newAccount = new Checking(newAccountNumber, (accountNumber1.balance + accountNumber2.balance));
}
}
这是我的帐户类:
class Account
{
private readonly int _accountNumber;
protected double balance;
public AccountStatus Status { get; set; }
public Account() { }
public Account(int accountNumber, double balance)
{
this._accountNumber = accountNumber;
this.balance = balance;
}
public double Balance
{
get;
private set;
}
}
我在帐户类中有更多方法,但我不需要它们来回答这个问题。
问题是,如何为 accountNumber1 和 accountNumber2 指定余额,因为余额以红色突出显示。我不确定如何访问余额。
(accountNumber1.balance + accountNumber2.balance)
烙印99
相关分类