Use delegate : delegate Event : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » delegate Event »

 

Use delegate









    

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 */
using System;

namespace Client.Chapter_8___Delegates_and_Events
{
  public delegate void MyDelegateEventHandler(int i);
  
  public class MyEventSubscriberChapter_8___Delegates_and_Events
  {
    static void Main(string[] args)
    {
      MyEventPublisher EventPublisher = new MyEventPublisher();
      

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

      EventPublisher.MyEvent += MyAnonymousDelegate;
      
      EventPublisher.DoSomething();
    }
    
  }
  
  public class MyEventPublisher
  {
    public event MyDelegateEventHandler MyEvent;
    public int DoSomething()
    {
      MyEvent(5);
      return 0;
    }
  }

}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» delegate Event