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