This is my class:
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;
}
}
}
I have highlighted the method called Withdraw which I think is creating a problem. It is suppose to check if the balance is less than Minimum balance and throw an exception. Lets say when I set the MinBalance to 500 and Balance to 1000 and then try to withdraw 600 out of 1000 then it should throw an exception saying insufficient balance, but it is not working in the first go but rather working when I try to withdraw the second time.
You’ll have to check not your currente Balance but how your Balance will be after you Withdraw, thats why it is not working as you expect, you can do it like this: