event demo
程序员文章站
2022-06-13 08:01:54
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespac... ......
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.diagnostics; namespace consoleapp392 { class program { static void main(string[] args) { adult adult = new adult(18); adult.adultevent += adult_adultevent; adult.age = 20; console.readline(); } private static void adult_adultevent(object sender, adultargs e) { string msg = string.empty; int newage = e.adultage; if(newage>=18) { msg = "adult"; } else { msg = "adolescent"; } console.writeline($"the newly updated age is {newage} and it's {msg} "); } } public class adultargs { public int adultage { get; set; } public adultargs(int age) { adultage = age; } } public class adult { public event eventhandler<adultargs> adultevent; public adult(int adultage) { age = adultage; } private int agevalue; public int age { get { return agevalue; } set { if(value!=agevalue) { agevalue = value; raisepropertychanged(value); } } } private void raisepropertychanged(int value) { adultevent?.invoke(this, new adultargs(value)); } } }
上一篇: ECMAScript 6 之Module
推荐阅读
-
event.x,event.clientX,event.offsetX区别_javascript技巧
-
Oracle Table Demo语句应用介绍
-
RTTI实现机制demo
-
std::shared_ptr简单用法demo
-
整理的比较全的event对像在ie与firefox浏览器中的区别_javascript技巧
-
使用php完成一个用户注册以及管理的demo(php实现单文件与多文件的上传)
-
对layui中的onevent 和event的使用详解
-
Azure Storage Rest API Demo
-
JavaScript 运行机制详解再浅谈Event Loop
-
QT Demo 之 calqlatr(2) calqlatr.qml