Bank.DepositAccount.Withdraw C# (CSharp) Метод

Withdraw() публичный Метод

public Withdraw ( int withdraw ) : void
withdraw int
Результат void
        public void Withdraw(int withdraw)
        {
            if ((this.Balance + withdraw) >= 0)
            {
                this.Balance += withdraw;
            }
            else
            {
                throw new ApplicationException("You cannot withdraw more money than you have!");
            }
        }
    }

Usage Example

Пример #1
1
        static void Main()
        {
            DepositAccount myDeposit = new DepositAccount(Customer.Individual, 0, 1);
            myDeposit.Deposit(2500);

            Console.WriteLine("Balance: {0}", myDeposit.Balance);
            Console.WriteLine("Interest: {0}", myDeposit.CalculateInterest(12));

            Console.WriteLine("... Withdrawing $2000 ...");
            myDeposit.Withdraw(-2000);
            // myDeposit.Withdraw(-2800); - this will throw exeption

            Console.WriteLine("New Balance {0}", myDeposit.Balance);
            Console.WriteLine("new Interest: {0}", myDeposit.CalculateInterest(12));
        }
All Usage Examples Of Bank.DepositAccount::Withdraw