delegate and event : Delegate event : Delegate C# Examples


C# Examples » Delegate » Delegate event »

 

delegate and event









    
using  System;

public  delegate  void  EventHandler(int  i);

class  MainClass
{
    static  void  Main(string[]  args)
    {
        MyEventPublisher  EventPublisher  =  new  MyEventPublisher();
        

        EventHandler  MyAnonymousDelegate  =  delegate(int  x)
        {
            Console.WriteLine("Anonymous  Event  FIRED!");
        };

        EventPublisher.MyEvent  +=  MyAnonymousDelegate;
        
        EventPublisher.DoSomething();
    }
    
}

public  class  MyEventPublisher
{
    public  event  EventHandler  MyEvent;
    public  int  DoSomething()
    {
        MyEvent(5);
        return  0;
    }
}
    
   
  
   



Output

Anonymous Event FIRED!


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Delegate
» Delegate event