Beispiel #1
0
        public static void Main()
        {
            MyTestApp TestApp = new MyTestApp();

            //Assign the method to be called when the event is fired
            TestApp.MyHandler = new EventHandler(TestApp.Hello);

            //Firing the event
            if (TestApp.MyHandler != null)
            {
                TestApp.MyHandler();
            }
        }
Beispiel #2
0
        public static void Main()
        {
            MyTestApp TestApp = new MyTestApp();

            //Add actions to the collection
            TestApp.EventActions += TestApp.Hello;
            TestApp.EventActions += TestApp.Goodbye;
            //Invoke all event actions
            if (TestApp.EventActions != null)
            {
                //this peculiar syntax hides the invoke
                TestApp.EventActions();
                //using the 'ActionCollection' idea:
                // foreach(EventAction action in TestApp.EventActions)
                //     action.Invoke();
            }
        }