您的位置:首页 > 编程语言 > C#

C# 为一个方法添加事件的方法 Event delegate

2006-05-19 09:06 465 查看
using System;

public delegate void LogEventHandler(object source, LogEventArgs args);

public class EventDemo
{
    public event LogEventHandler logEvent;

    public void Do()
    {
        logEvent(this,new LogEventArgs());

        Console.WriteLine("Ok.");
    }
}
public class LogEventArgs : EventArgs
{
    public LogEventArgs()
    {}

}
public class App
{
    public static void Main()
    {
     EventDemo eventDemo =new EventDemo();
     eventDemo.logEvent += new LogEventHandler(WriteLog);

     eventDemo.Do();

    }
    public static void WriteLog(object sender,LogEventArgs le)
    {
     Console.WriteLine("In Event :Write Done. ");
    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# class object system
相关文章推荐