📄 account.cs
字号:
using System;
namespace MSPress.CSharpCoreRef.Bank
{
public class Account
{
public delegate bool DebitPolicy(decimal aWithdrawal);
public Account(decimal anInitialBalance,
DebitPolicy aDebitPolicy)
{
_balance = anInitialBalance;
_debitPolicy = aDebitPolicy;
}
public decimal Balance
{
get
{
return _balance;
}
}
public void Deposit(decimal aDeposit)
{
if(aDeposit < 0)
throw new ArgumentOutOfRangeException();
_balance += aDeposit;
}
public bool Withdrawal(decimal aWithdrawal)
{
if(aWithdrawal < 0)
throw new ArgumentOutOfRangeException();
if(aWithdrawal < _balance)
{
_balance -= aWithdrawal;
return true;
}
else
{
// If no debit policy, no overdrafts are permitted.
if(_debitPolicy == null)
return false;
aWithdrawal -= _balance;
if(_debitPolicy(aWithdrawal))
{
_balance = 0;
return true;
}
else
{
return false;
}
}
}
protected DebitPolicy _debitPolicy;
protected decimal _balance;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -