C#事件EventHandle、Event的使用
在C#绝大多数的事件开发中,优先使用.net自带的EventHandle事件来编写事件处理。可以解决绝大部分的事件操作,另外有一小部分可以使用委托,加event事件来自定义事件编写,比如在进行自定义控件的事件时使用Eventhandle在控件事件浏览器中找不到,只能使用委托加事件的方式。 EventHandle来编写事件处理的范例 参考链接地址 https://docs.microsoft.com/zh-cn/dotnet/api/system.eventhandler?redirectedfrom=MSDN&view=netframework-4.8 using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Counter c = new Counter(new Random().Next(10)); c.ThresholdReached += c_ThresholdReached; Console.WriteLine("press 'a' key to increase total"); while (Console.ReadKey(true).KeyChar == 'a') { Console.WriteLine("adding one");