Use the bult-in EventHandler delegate : delegate Event : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » delegate Event »

 

Use the bult-in EventHandler delegate









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Use the bult-in EventHandler delegate. 
  
using System; 
 
// Declare an event class. 
class MyEvent { 
  public event EventHandler SomeEvent; // uses EventHandler delegate 
 
  // This is called to fire SomeEvent. 
  public void OnSomeEvent() { 
    if(SomeEvent != null) 
      SomeEvent(this, EventArgs.Empty); 
  } 
} 
 
public class EventDemo6 { 
  static void handler(object source, EventArgs arg) { 
    Console.WriteLine("Event occurred"); 
    Console.WriteLine("Source is " + source); 
  } 
 
  public static void Main() {  
    MyEvent evt = new MyEvent(); 
 
    // Add handler() to the event list. 
    evt.SomeEvent += new EventHandler(handler); 
 
    // Fire the event. 
    evt.OnSomeEvent(); 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» delegate Event