C# 6.0 Pocket Reference by Joseph Albahari and Ben Albahari

C# 6.0 Pocket Reference by Joseph Albahari and Ben Albahari

Author:Joseph Albahari and Ben Albahari
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media, Inc.
Published: 2015-10-16T00:00:00+00:00


public delegate void EventHandler<TEventArgs> (object source, TEventArgs e) where TEventArgs : EventArgs;

Note

Before C# 2.0 (when generics were added to the language) the solution was to instead write a custom event handling delegate for each EventArgs type as follows:

delegate void PriceChangedHandler (object sender, PriceChangedEventArgs e);

For historical reasons, most events within the Framework use delegates defined in this way.

A protected virtual method, named On-event-name, centralizes firing of the event. This allows subclasses to fire the event (which is usually desirable) and also allows subclasses to insert code before and after the event is fired.

Here’s how we could use our Stock class:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.