日期:2014-05-18 浏览次数:20561 次
//A.cs
class A
{
public delegate void EventHandler(object sender, EventArgs e);
public event EventHandler AEvent;
public foo()
{
AEvent(this, new EventArgs());
}
}
//Program.cs
static void Main(string[] Args)
{
A a = new A();
a.AEvent += new A.EventHandler(On_AEvent);
a.foo();
}
static void On_AEvent(object sender, EventArgs e)
{
Console.WriteLine("On_AEvent");
}
------解决方案--------------------
//A.cs
class A
{
public delegate void EventHandler(object sender, EventArgs e);
public event EventHandler AEvent;
public void foo()
{
AEvent(this, new EventArgs());
}
}
//Program.cs
static void Main(string[] Args)
{
A a = new A();
a.AEvent += new A.EventHandler(On_AEvent);
a.foo();
}
static void On_AEvent(object sender, EventArgs e)
{
Console.WriteLine("On_AEvent");
}