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