日期:2014-05-17 浏览次数:20770 次
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Bank b = new Bank(); b.BeforeClosed +=new Bank.BeforeBankCloseHandler(b_BeforeClosed); b.Close(); } static void b_BeforeClosed(object sender, BeforeBankCloseEventArgs e) { Console.WriteLine("Bank'Name is:"+e.BankName); Console.WriteLine("Before bank is closed,I can do something"); } } public class Bank { public delegate void BeforeBankCloseHandler(object sender, BeforeBankCloseEventArgs e); public event BeforeBankCloseHandler BeforeClosed; public void Close() { string bName = "China Bank"; BeforeBankCloseEventArgs arg = new BeforeBankCloseEventArgs(bName); BeforeClosed(this, arg); Console.WriteLine("Bank Closed"); } } public class BeforeBankCloseEventArgs : EventArgs { public BeforeBankCloseEventArgs(string m) { _bankName = m; } private string _bankName; public string BankName { get { return _bankName; } set { _bankName = value; } } } }
------解决方案--------------------
http://topic.csdn.net/u/20090227/16/9f795a88-45b5-47c7-b68e-a83ae0d74fd8.html