接口中事件的实现
一下是一个接口中实现事件的代码,看不懂,还请高手解释下.先谢谢了。public delegate void TestDelegate(); // delegate declaration
public interface ITestInterface
{
event TestDelegate TestEvent;
void FireAway();
}
public class TestClass : ITestInterface
{
public event TestDelegate TestEvent;
public void FireAway()
{
if (TestEvent != null)
{
TestEvent();
}
}
}
public class MainClass
{
static private void F()
{
System.Console.WriteLine("This is called when the event fires.");
}
static void Main()
{
ITestInterface i = new TestClass();
i.TestEvent += new TestDelegate(F);
i.FireAway();
}
}
i.TestEvent += new TestDelegate(F);这个怎么理解呢?