static void Main(string[] args) { MyNotifier notifier = new MyNotifier(); notifier.SomethingHappend += new EventHandler(MyHandler); for (int i = 1; i < 30; i++) { notifier.DoSomething(i); } }
static void EventTest() { WriteLine("\nEventTest()"); void MyHandler(string message) { WriteLine(message); } MyNotifier notifier = new MyNotifier(); notifier.SomethingHappened += new EventHandler(MyHandler); for (int i = 0; i < 30; i++) { notifier.DoSomething(i); } //Ex13_2 WriteLine("\nEx13_2"); void PrizeMessage(int CustomerNo) { WriteLine($"축하합니다! {CustomerNo}번째 고객 이벤트에 당첨되셨습니다."); } void SecurityMessage(int CustomerNo, string Action) { WriteLine($"No.{CustomerNo} : {Action}"); } Market market = new Market(); market.CustomerEvent += new MarketDelegate(PrizeMessage); market.SecurityEvent += new SecurityDelegate(SecurityMessage); for (int CustomerNo = 0; CustomerNo < 100; CustomerNo++) { market.BuySomething(CustomerNo); } WriteLine(); string[] CustomerActionArray = { "Buy", "Buy", "Buy", "Stealing", "Buy", "Buy", "Stealing", "Buy" }; for (int i = 0; i < CustomerActionArray.Length; i++) { market.BuySomething(i, CustomerActionArray[i]); } }