日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

猫大叫,鼠速逃,人醒了

發布時間:2023/12/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 猫大叫,鼠速逃,人醒了 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? 一道.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

總結

以上是生活随笔為你收集整理的猫大叫,鼠速逃,人醒了的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。