国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海口市| 辽源市| 德清县| 连城县| 长丰县| 虹口区| 广南县| 沂南县| 阳城县| 永嘉县| 丰都县| 团风县| 湄潭县| 共和县| 新乡市| 肥西县| 乐清市| 陇川县| 灵寿县| 仁寿县| 闸北区| 原阳县| 常德市| 喀喇沁旗| 百色市| 扶余县| 嵊泗县| 突泉县| 浑源县| 海盐县| 巴马| 西充县| 高要市| 阳谷县| 抚州市| 灵川县| 修文县| 修文县| 修文县| 贵溪市| 砀山县|