static void Main(string[] args) { PiggyBank pb = new PiggyBank(); pb.BalanceChanged += (amount) => Console.WriteLine("The balance amount is {0}", amount); pb.BalanceChanged += (amount) => { if (amount > 500.0m) { Console.WriteLine("You reached your savings goal! You have {0}", amount); } }; string theStr; do { Console.WriteLine("How much to deposit?"); theStr = Console.ReadLine(); if (!theStr.Equals("exit")) { decimal newVal = decimal.Parse(theStr); pb.TheBalance += newVal; } } while (!theStr.Equals("exit")); }
static void Main(string[] args) { PiggyBank pb = new PiggyBank(); pb.balanceChanged += (amount) => Console.WriteLine("The balance amount is {0}", amount); pb.balanceChanged += (amount) => { if (amount > 500.0m) Console.WriteLine("You reached your savings goal! You have {0}", amount); }; string theStr; do { Console.WriteLine("How much to deposit?"); theStr = Console.ReadLine(); if (!theStr.Equals("exit")) { decimal newVal = decimal.Parse(theStr); pb.theBalance += newVal; } } while (!theStr.Equals("exit")); }