猫大叫,鼠速逃,人醒了
生活随笔
收集整理的這篇文章主要介紹了
猫大叫,鼠速逃,人醒了
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? 一道.Net程序員面試題的討論:貓大叫,鼠速逃,人醒了。
考慮:(1)聯動性
(2)可擴展性
編程實現它。
試了一下.
??1?using?System;
??2?
??3?namespace?demo_2
??4?{
??5?????///?<summary>
??6?????///?Class2?的摘要說明。
??7?????///?</summary>
??8?????public?delegate?void?delegate_handler(object?sender,EventArgs?e);
??9?????public?class?Class2
?10?????{
?11?????????
?12?????????///?<summary>
?13?????????///?應用程序的主入口點。
?14?????????///?</summary>
?15?????????[STAThread]
?16?????????static?void?Main(string[]?args)
?17?????????{
?18?????????????Cat??objCat?=?new?Cat();
?19?????????????Mouse??objMouse=new?Mouse();
?20?????????????Man??objMan=new?Man();
?21?????????????objCat.add_EventHandler(new?delegate_handler(objMouse.run));
?22?????????????objMouse.add_EventHandler(new?delegate_handler(objMan.wakeup));
?23?????????????objCat.CatCry();
?24?????????????
?25?????????}
?26?????}
?27?????public??class??Cat
?28?????{
?29?????????public?Cat()
?30?????????{
?31?????????????Console.WriteLine("產生貓");
?32?????????}
?33?????????public?event?delegate_handler?Cry;?
?34?????????protected?virtual?void?OnCry(EventArgs?e)?
?35?????????{?
?36?????????????if(Cry?!=?null)?
?37?????????????{?
?38?????????????????Cry(this,e);?
?39?????????????}?
?40?????????}
?41?????????public?void?add_EventHandler(delegate_handler?dh)
?42?????????{
?43?????????????if(dh==null)
?44?????????????{
?45?????????????????Cry=dh;
?46?????????????}
?47?????????????else
?48?????????????{
?49?????????????????Cry?+=dh;?
?50?????????????}
?51?
?52?????????}
?53?????????public??void???CatCry()
?54?????????{
?55?????????????Console.WriteLine("貓叫了");?
?56?????????????System.Threading.Thread.Sleep(500);?
?57?????????????OnCry(new?System.EventArgs());
?58?????????}
?59?????}?
?60?????public??class??Mouse
?61?????{
?62?????????public?Mouse()
?63?????????{
?64?????????????Console.WriteLine("產生老鼠");
?65?????????}
?66?????????public?event?delegate_handler?MouseRun;
?67?????????protected?virtual?void?OnRun(EventArgs?e)?
?68?????????{?
?69?????????????if(MouseRun?!=?null)?
?70?????????????{?
?71?????????????????MouseRun(this,e);?
?72?????????????}?
?73?????????}
?74?????????public?void?add_EventHandler(delegate_handler?dh)
?75?????????{
?76?????????????if(dh==null)
?77?????????????{
?78?????????????????MouseRun=dh;
?79?????????????}
?80?????????????else
?81?????????????{
?82?????????????????MouseRun?+=dh;?
?83?????????????}
?84?
?85?????????}
?86?????????public?void?run(object?sender,EventArgs?e)?
?87?????????{?
?88?????????????Console.WriteLine("老鼠逃了");?
?89?????????????System.Threading.Thread.Sleep(500);?
?90?????????????OnRun(new?System.EventArgs());
?91?????????}?
?92?????}
?93?????public??class?Man
?94?????{
?95?????????public?Man()
?96?????????{
?97?????????????Console.WriteLine("產生人");
?98?????????}
?99?????????public?void?wakeup(object?sender,EventArgs?e)?
100?????????{?
101?????????????Console.WriteLine("人醒了");?
102?????????}?
103?????}
104?}
?
轉載于:https://www.cnblogs.com/Jodan/archive/2007/02/27/658565.html
總結
以上是生活随笔為你收集整理的猫大叫,鼠速逃,人醒了的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 利用系统剪贴板 保存 自定义对象
- 下一篇: “欢迎光临”用其他各国语言怎么写、怎么说