C # An example of how delegates and events are understandable

Source: Internet
Author: User

1 usingSystem;2 3 namespaceTest4 {5      Public classRoommate6     {7          Public Delegate voidThis is a delegate ();8 9          Public voidwake up to the morning run ()Ten         { OneConsole.WriteLine ("Roommate: Hey, get up! "); A             ifWhat do you do if you ask someone to get up?NULL)//If someone entrusts me with something -             { - What to do when someone gets up ? the             } -Console.WriteLine ("roommate: Get out of here and run in the morning! "); -         } -  +          Public EventThis is a commission to ask someone to get up to do what to do; -     } +  A      Public classto read me in the morning at     { -          Public voidWake up Morning reading () -         { -Console.WriteLine ("me: Oh, get up!!! "); -Console.WriteLine ("I: 12345, read the Internet to know, brush up after the morning reading! "); -         } in     } -  to      Public classWang Ba Duzi +     { -          Public voidbet five cents to start () the         { *Console.WriteLine ("Wang Ba Duzi: Five Mao take away, Labor to break sleep! "); $         }Panax Notoginseng     } -  the     class Program +     { A         Static voidMain (string[] args) the         { +  -             varChinese Good roommate =Newroommate (); $             varme =Newto read me in the morning (); $             varWang Ba Duzi =NewWang Ba Duzi (); -  -             //Let me tell my roommate: I need to get up early to read theGood roommate in China. Why do you have to get up? + =I get up and read in the morning; -             //Wang Duzi to stir the crap.WuyiGood roommate in China. Why do you have to get up? + =Wang eight duzi. Five cents on the horse does not come; the             //so the next day came. -Console.WriteLine ("alarm: Seven o'clock in the morning ..."); WuConsole.WriteLine ("system tip: Roommates Get up! "); - good roommate in China. Get up in the morning and run Away (); About         } $     } -}

C # An example of how delegates and events are understandable

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.