示例#1
0
        static void Main(string[] args)
        {
            Person           junaid = new Person("junaid mahmood is my name");
            Person           Amamr = new Person("My name is Ammar Mahmood");
            messageProcessor message1, message2, staticMessage, anotherMethod;

            message1      = new messageProcessor(junaid.Say);
            message2      = new messageProcessor(Amamr.Say);
            staticMessage = new messageProcessor(background.Note);
            //  anotherMethod = new messageProcessor(Program.saySome);
            //   message1("hey junaid how are you");
            //  message2.Invoke("hello buddy ammar how r u ");
            //  staticMessage("statc message clal");
            anotherMethod  = message1;
            anotherMethod += message2;
            anotherMethod += staticMessage;

            anotherMethod("multi delegate ...");

            // Video Encoder class delegate
            var vid        = new video()
            {
                Title = "First Video "
            };
            var vEncoder = new videoEncoder();  // publisher
            var mail       = new mailService(); // subscriver
            var msgService = new messageService();

            vEncoder.videoEncoded += mail.onVideoEncoded;
            vEncoder.videoEncoded += msgService.videoEncoded;
            vEncoder.Encode(vid);
            Console.ReadLine();
        }
 protected virtual void onVideoEncoded(video v)
 {
     if (videoEncoded != null)
     {
         videoEncoded(this, new videoEventArgs()
         {
             video = v
         });
     }
 }
 public void Encode(video v)
 {
     Console.WriteLine("Video is Encoded ...");
     onVideoEncoded(v);
 }