Use the bult-in EventHandler delegate : delegate Event « Language Basics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Language Basics » delegate Event 




Use the bult-in EventHandler delegate
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()
  
}


           
       














Related examples in the same category
1.A very simple event demonstrationA very simple event demonstration
2.An event multicast demonstrationAn event multicast demonstration
3.Individual objects receive notifications when instance event handlers are usedIndividual objects receive notifications when instance 
   event handlers are used
4.A class receives the notification when a static method is used as an event handlerA class receives the notification when  
   a static method is used as an event handler
5.Create a custom means of managing the event invocation listCreate a custom means of managing the event invocation list
6.Use delegate: eventUse delegate: event
7.Delegate and event hierarchyDelegate and event hierarchy
8.Events:Add and Remove FunctionsEvents:Add and Remove Functions
9.Events:Add and Remove Functions 2Events:Add and Remove Functions 2
10.Events: Custom Add and RemoveEvents: Custom Add and Remove
11.Delegates And EventsDelegates And Events
12.Delegates And Events 2Delegates And Events 2
13.Chaining events.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.