ASP.NET如何在类中编写一个事件问题

2025-03-04 11:08:57
推荐回答(1个)
回答1:

class Myclass
{
public event EventHandler Myevent;

public Myclass()
{
Myevent += new EventHandler(Myclass_Myevent);
}
//触发事件函数
public void fun()
{
Myevent(null ,new EventArgs ());
}

void Myclass_Myevent(object sender, EventArgs e)
{
//some code
}
}

在主函数里掉用fun()方法就会触发事件