示例#1
0
        static void Main(string[] args)
        {
            // creating custom delegates and passed in the callback
            // change it int to make a return type function
            WorkPerformedhandler del1 = new WorkPerformedhandler(WorkPerformed1);
            WorkPerformedhandler del2 = new WorkPerformedhandler(WorkPerformed2);
            WorkPerformedhandler del3 = new WorkPerformedhandler(WorkPerformed3);


            // added del2 and del3 to invokation list
            del1 += del2;
            del1 += del3;


            // you can only have one return type here when you invoke the
            // delegate.(we hold one value here)
            int finalHours = del1(10, WorkType.GenerateReports);

            //the last deleate in invocation list is the one
            // where the return value will come back
            Console.WriteLine(finalHours);



            Console.Read();
        }
示例#2
0
 static void DoWork(WorkPerformedhandler del)
 {
     // invoke a delegate
     del(5, WorkType.GoToMeetings);
 }