[C#] C# 定义一个简单的事件(Event) →→→→→进入此内容的聊天室

来自 , 2021-04-04, 写在 C#, 查看 149 次.
URL http://www.code666.cn/view/46c67bed
  1. public class MyClass : IDisposable
  2. {
  3.    public event EventHandler Disposing;  
  4.  
  5.    public void Dispose()
  6.    {
  7.       // release any resources here
  8.       if (Disposing != null)
  9.       {
  10.          // someone is subscribed, throw event
  11.          Disposing (this, new EventArgs());
  12.       }
  13.    }
  14.  
  15.    public static void Main( )
  16.    {
  17.       using (MyClass myClass = new MyClass ())
  18.       {
  19.          // subscribe to event with anonymous delegate
  20.          myClass.Disposing += delegate
  21.             { Console.WriteLine ("Disposing!"); };
  22.       }
  23.    }
  24. }
  25. //csharp/4157

回复 "C# 定义一个简单的事件(Event)"

这儿你可以回复上面这条便签

captcha