|
/* Copyright (C) Dmitri Nesteruk */
namespace ConsoleApplication1
{
using System;
/// <summary>
///
/// </summary>
public sealed class Account
{
private int balance;
public int Balance
{
get { return balance; }
set { balance = value; }
}
public void Deposit(int amount)
{
//if (amount <= 0)
//throw new Exception();
balance += amount;
}
public void Withdraw(int amount)
{
if (amount > balance)
throw new Exception();
balance -= amount;
}
public static void Transfer(Account from, Account to, int amount)
{
if (from == null) throw new ArgumentNullException("from");
if (to == null) throw new ArgumentNullException("to");
if (amount <= 0) throw new ArgumentException("Transfer amount must be positive");
from.Withdraw(amount);
to.Deposit(amount);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I work primarily with the .NET technology stack, and specialize in accelerated code production via code generation (static or dynamic), aspect-oriented programming, MDA, domain-specific languages and anything else that gets products out the door faster. My languages of choice are C# and C++, though I'm open to suggestions.