国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【轉載】#370

2019-11-17 03:18:20
字體:
來源:轉載
供稿:網友

【轉載】#370 - Subscribe to an Event by Adding an Event Handle

You subscribe to a particular event in C# by defining an event handler-code that will be called whenever the event occurs (is raised). You then attach your event handler to an event on a specific object, using the += Operator.

Below is an example where we define an event handler for the Dog.Barked event. Each time that kirby barks, we'll record the date and time of the bark in a list.

 1 PRivate static List<DateTime> barkLog = new List<DateTime>(); 2  3 static void Main() 4 { 5     Dog kirby = new Dog("Kirby", 12); 6     kirby.Barked += new EventHandler(kirby_Barked); 7  8     kirby.Bark(); 9     Console.ReadLine();10 11     kirby.Bark();12     Console.ReadLine();13 }14 15 // Neither argument is used, for the moment16 static void kirby_Barked(object sender, EventArgs e)17 {18     // Log kirby's barks19     barkLog.Add(DateTime.Now);20 }

Assuming that the Dog class fires its Barked event whenever we call the Bark method, our handler will get called whenever kirby barks.

原文地址:#370 - Subscribe to an Event by Adding an Event Handle


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 太仆寺旗| 和平县| 凤山市| 苍山县| 大港区| 定兴县| 邹平县| 股票| 丹寨县| 泗阳县| 安远县| 莱州市| 神农架林区| 乐至县| 敦煌市| 青河县| 西乌珠穆沁旗| 西吉县| 凤台县| 滨州市| 凤山县| 延安市| 修武县| 滨州市| 巨野县| 宜兰县| 南召县| 高唐县| 上高县| 三河市| 瑞安市| 通辽市| 甘泉县| 宜阳县| 唐河县| 青铜峡市| 兰溪市| 遂宁市| 萨嘎县| 中阳县| 漳平市|