事件:
public class1
{
delegatevoid EventHandler();
publicevent EventHadler Update;
publicvoid Notify()
{
if(Update!=null)
Update();
}
}
注:此委托只能注册无参数无返回值的方法。
在使用class1的时候,可以用:事件+=委托(事件处理程序) 的形式使用,如:
class1 demo=new class1();
demo.Update+=new EventHandler(Method);
public void Method()
{....}
委托:
public class1
{
public delegate void FocuseEventHandler(string title);
public class1()
{
FocuseEventHandler focusdelege =test;
//或者FocuseEventHandler focusdelege =new FocuseEventHandler(test);
focusdelege("22");
}
private void test(string xx)
{
}