public static void BuyCandy(PiggyBank piggyBank) { if (piggyBank.Coins < 7) throw new ArgumentException( "Not enough money for candy!", "piggyBank"); piggyBank.Coins -= 7; }
public static void TestMutable() { // this works fine var piggyBank = new PiggyBank(5); MutableTest.DepositCoins(piggyBank); MutableTest.BuyCandy(piggyBank); // but this raises an ArgumentException piggyBank = new PiggyBank(5); MutableTest.BuyCandy(piggyBank); MutableTest.DepositCoins(piggyBank); }
public static void DepositCoins(PiggyBank piggyBank) { piggyBank.Coins += 10; }