C#:实现接口中定义的事件

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();

     }

 }
View Code

 

你可能感兴趣的:(C#)