A very simple event demonstration. : Delegate event : Delegate C# Examples


C# Examples » Delegate » Delegate event »

 

A very simple event demonstration.









    
using  System;  
  
delegate  void  MyEventHandler();  
  
class  MyEvent  {  
    public  event  MyEventHandler  SomeEvent;  
  
    public  void  OnSomeEvent()  {  
        if(SomeEvent  !=  null)  
            SomeEvent();  
    }  
}  
  
class  MainClass  {  
    static  void  handler()  {  
        Console.WriteLine("Event  occurred");  
    }  
  
    public  static  void  Main()  {    
        MyEvent  evt  =  new  MyEvent();  
  
        evt.SomeEvent  +=  handler;  
  
        evt.OnSomeEvent();  
    }  
}
    
   
  
   



Output

Event occurred


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Delegate
» Delegate event