Popular rude events entrusted to understand

Source: Internet
Author: User

Simple and Rude event delegate understanding code

1 usingSystem;2 usingSystem.Collections.Generic;3 4  Public classMyClass5 {6      Public Static voidRunsnippet ()7     {8Header head=NewHeader ();9Xiashua xiashuaa=NewXiashua (head);TenXiashub xiashuab=NewXiashub (head); OneHead. Raise ("left"); AConsole.WriteLine ("================================"); -Head. Raise ("Right"); -Console.WriteLine ("================================"); the head. Fall (); - console.readline (); -     } -      +     #regionHelper methods -      +      Public Static voidMain () A     { at         Try -         { - Runsnippet (); -         } -         Catch(Exception e) -         { in             stringError =string. Format ("---\nthe following error occurred while executing the snippet:\n{0}\n---", e.tostring ()); - Console.WriteLine (error); to         } +         finally -         { theConsole.Write ("Press any key to continue ..."); * Console.readkey (); $         }Panax Notoginseng     } -  the     Private Static voidWL (ObjectTextparams Object[] args) +     { A Console.WriteLine (text.    ToString (), args);  the     } +      -     Private Static voidRL () $     { $ Console.ReadLine ();  -     } -      the     Private Static voidBreak () -     {Wuyi System.Diagnostics.Debugger.Break (); the     } -  Wu     #endregion - } About  $  -  Public     Delegate voidRaiseeventhandler (stringhand); -  Public Delegate voidFalleventhandler (); -  A  Public classHeader + { the      Public EventRaiseeventhandler RaiseEvent; -      Public EventFalleventhandler fallevent; $      the      Public voidRaise (stringhand) the     { theConsole.WriteLine ("The leader {0} to raise his hand", hand); the         if(raiseevent!=NULL) -         { in RaiseEvent (hand); the         } the     } About      the      Public voidFall () the     { theConsole.WriteLine ("Boss Wrestling Cup"); +         if(Fallevent! =NULL) -         { the fallevent ();Bayi         } the     } the } -  -  Public classXiashua the { the Header header ; the      PublicXiashua (Header _head) the     { -          This. header=_head; the          This. header. raiseevent+=NewRaiseeventhandler (fallraise); the          This. header. fallevent+=NewFalleventhandler (fallhand); the     }94      the      Public voidFallraise (stringhand) the     { the         if(hand=="left")98         { About Attach ();  -         }101     }102      Public voidFallhand ()103     {104 Attach (); the     }106     107      Public voidAttach ()108     {109Console.WriteLine ("Xiashua Immediate Attack"); the     }111 } the 113  Public classXiashub the { the Header header ; the      PublicXiashub (Header _head)117     {118          This. header=_head;119          This. header. raiseevent+=NewRaiseeventhandler (fallraise); -          This. header. fallevent+=NewFalleventhandler (fallhand);121     }122     123      Public voidFallraise (stringhand)124     { the         if(hand=="Right")126         {127 Attach ();  -         }129     } the      Public voidFallhand ()131     { the Attach ();133     }134     135      Public voidAttach ()136     {137Console.WriteLine ("Xiashubb Immediate Attack");138     }139}

Popular rude events entrusted to understand

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.