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

相关文章:

  • 2022-03-04
  • 2021-11-18
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-12-14
  • 2022-02-01
  • 2022-12-23
相关资源
相似解决方案