using System; using System.Collections.Generic; using System.Text; namespace delegate_event { public delegate void simple_event(int n); // Declare an event class. class del_event { public event simple_event fire_event; // This is called to fire the event. public void Onfire_event(int nn) { if (fire_event != null) fire_event(nn); int n10 = 10 * nn; Console.WriteLine("Passing through events : " + n10); } } class test { // An event call_event. static void call_event(int m) { Console.WriteLine("Access an event with a value = " + m); } public static void Main() { Console.WriteLine(); Console.Write("Enter an Integer : "); int t = Int32.Parse(Console.ReadLine()); del_event evt = new del_event(); // Add call_event() to the event list. evt.fire_event += new simple_event(call_event); // Fire the event. evt.Onfire_event(t); Console.ReadLine(); } } } |
cursor returns from command line to the debug phase, initializing event
|
receives a value
|
Cursor plunges to the method call_event
|
Delegate (Fire-Fire ---> ) routine via delegate
|
Back to the called of the event
|
end product |