C # Delegate base 2--multi-way delegate

Source: Internet
Author: User

C # commissioned the basic series was originally published in February 2011 in my Sina blog, now it will be like this blog.

Multi-Channel delegation

Class Program {public delegate void Saythingtos (string s);
        void SayHello (String s) {Console.WriteLine ("Hello {0}", s);
        } void Saygoodbye (String s) {Console.WriteLine ("Goodbye {0}", s);
            } static void Main (string[] args) {//mode one Saythingtos say1, Say2, Say3, Say4;
            Program P = new program ();
            Say1 = P.sayhello; Say1 ("XY");
            Hello xy say2 = P.saygoodbye; Say2 ("XY");
            Goodbye xy say3 = say1 + say2; Say3 ("XY");
            Hello xy, bye xy say4 = say3-say1; Say4 ("XY");
            Goodbye XY//mode two saythingtos S1 = new Saythingtos (P.sayhello);
            S1 + = new Saythingtos (P.saygoodbye); S1 ("XY");
            Hello xy, bye xy saythingtos s2 = new Saythingtos (P.sayhello);           
            S2 + = new Saythingtos (P.saygoodbye); S2-= new SaythingtOS (P.sayhello); S2 ("XY");

 Goodbye XY}}

This article refers to the content of the agent from Jin Xu-liang's ". NET 4.0 object-oriented Programming"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.