예제 #1
0
        public static void Main(string[] args)
        {
            // Wiring up the delegate pipeline to event handler.
            DoTheWorkHandler del  = new DoTheWorkHandler(DoTheWork);
            DoTheWorkHandler del1 = new DoTheWorkHandler(DoOtherWork);
            DoTheWorkHandler del2 = new DoTheWorkHandler(DoYetMoreWork);

            // order matters on multicast delegate
            del += del1 + del2;

            // FYI: the last delegate return value is the one that is used. They are not 'accumulated'.
            //int finalHours = del("Chris", WorkType.Shopping);
            //Console.WriteLine($"finalHours: {finalHours}");

            Worker work = new Worker();

            work.DoWork("Monday", WorkType.Shopping);


            Console.Read();             // Exit run
        }
예제 #2
0
 // Invoke the delegate
 static void DoWork(DoTheWorkHandler del) => del("Chris", WorkType.Work);