예제 #1
0
        public static void BuyCandy(PiggyBank piggyBank)
        {
            if (piggyBank.Coins < 7)
                throw new ArgumentException(
                  "Not enough money for candy!", "piggyBank");

            piggyBank.Coins -= 7;
        }
예제 #2
0
        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);
        }
예제 #3
0
 public static void DepositCoins(PiggyBank piggyBank)
 {
     piggyBank.Coins += 10;
 }