I am using C# and Visual Studio 2015.
I have two classes BankAccount and Wallet. Wallet class has a transfer method that calls an instance of BankAccount. However, on my form code when I send those parameters, it is not withdrawing funds from the source and destination balances.
transfer method:
public void TransferFund(BankAccount source, BankAccount destination, double amount)
{
double Source = source.Balance;
double Destination = destination.Balance;
if (Source > amount)
{
Source -= amount;
Destination += amount;
}
else
{
throw new ArgumentException("Insufficient funds for transfer.");
}
}
on form button click:
BankAccount from = lbTransferFrom.SelectedItem as BankAccount;
BankAccount to = lbTransferFrom.SelectedItem as BankAccount;
Wallet wall = new Wallet();
double amount = Convert.ToDouble(tbAmount.Text);
wall.TransferFund(from, to, amount);
Question: How do I get the source and destination objects to actually change the balances as it should?