C# 定义一个简单的事件(Event)
public class MyClass : IDisposable { public event EventHandler Disposing; public void Dispose() { // release any resources here if (Disposing != null) { // someone is subscribed, throw event Disposing (this, new EventArgs()); } } public static void Main( ) { using (MyClass myClass = new MyClass ()) { // subscribe to event with anonymous delegate myClass.Disposing += delegate { Console.WriteLine ("Disposing!"); }; } } }