static void Main(string[] args) { PiggyBank pb = new PiggyBank(); BalanceLogger bl = new BalanceLogger(); BalanceWatcher bw = new BalanceWatcher(); pb.balanceChanged += bl.balanceLog; pb.balanceChanged += bw.balanceWatch; 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(); BalanceLogger bl = new BalanceLogger(); BalanceWatcher bw = new BalanceWatcher(); pb.balanceChanged += bl.balanceLog; pb.balanceChanged += bw.balanceWatch; string theStr; do { Console.WriteLine("How much to deposit?"); decimal newVal; theStr = Console.ReadLine(); if (Decimal.TryParse(theStr, out newVal)) { newVal = decimal.Parse(theStr); pb.negBalanceChanged = delegate(object sender, BalanceArgs e) { if (pb.theBalance < 0) { Console.WriteLine(e.balance); } /*Console.WriteLine("{0} had the '{1}' property changed", sender.GetType(), e.balance);*/ }; pb.theBalance += newVal; } else { Console.WriteLine("Not a number"); pb.theBalance += 0; } } while (!theStr.Equals("exit")); }
static void Main(string[] args) { PiggyBank pb = new PiggyBank(); BalanceLogger bl = new BalanceLogger(); BalanceWatcher bw = new BalanceWatcher(); pb.BalanceChanged += bl.BalanceLog; pb.BalanceChanged += bw.BalanceWatch; 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")); }