c#事件的定义和使用

来源:互联网 发布:淘宝怎么提高店铺权重 编辑:程序博客网 时间:2024/05/18 21:50

public class1

{

delegate void EventHandler();

public event EventHadler Update;

public void Notify()

{

//if(...)

Update();

}

}

注:此委托只能注册无参数无返回值的方法。

在使用class1的时候,可以用:事件+=委托(事件处理程序) 的形式使用,如:

class1 demo=new class1();

demo.Update+=new EventHandler(Method);

public void Method()

{....}

 

0 0