这是我的课:
class EmpDetails
{
private string _EmpName;
private int _EmpID;
private string _EmpDepartment;
private string _EmpPosition;
private decimal _Balance;
private static int _PrevId;
public static decimal MinBalance; //This memeber is not working as required
**public void Withdraw(decimal amount) // The Problem is in this method**
{
if (this.Balance < MinBalance)
{
throw new ApplicationException("Insufficient funds");
}
else
{
this._Balance -= amount;
}
}
}
我已经强调了Withdraw
我认为会产生问题的方法。假设检查余额是否小于最小余额并抛出异常。假设当我将 MinBalance 设置为 500 并将 Balance 设置为 1000,然后尝试从 1000 中提取 600 时,它应该抛出一个异常,说余额不足,但它在第一次运行时不起作用,而是在我尝试提取时起作用第二次。