using System; using System.Collections.Generic; using System.Text; namespace EventDemo { /// /// 定义事件接收者 /// public class Fax { public Fax(MailManager mm) { // 构造委托实例,向事件登记回调方法 mm.NewMail += FaxMsg; } /// /// 回调方法 /// /// 表示MailManager对象,便于将信息传递给他 /// 表示MailManager对象想传给我们的附加信息 private void FaxMsg(object sender, NewMailEventArgs e) { Console.WriteLine("msg:{0},{1},{2}", e.From, e.To, e.Content); } /// /// 注销对事件的登记 /// /// public void Unregister(MailManager mm) { mm.NewMail -= FaxMsg; } } }