Visual Studio .NET provides a new set of features designed to improve and enhance the development experience. Most of these changes have to do with user ergonomics and are typical of a minor release of a Visual Studio product. Only a few of the changes are related to the underlying platform.
by Juval Löwy
May 9, 2003
Page 2 of 5
C# Automatic Event Hookup and Handler Generation
.NET delegate-based events are a type safe way to connect an event publisher to an event subscriber. Because the exact signature of the event handling method is known, IntelliSense can generate the code creating a new delegate object targeting the event handling method, and even the event handling method itself.
For example, consider the MyPublisher class, which is used to publish events to interested subscribers about changes to the value of some number:
public delegate void NumberChanged(int num);
public class MyPublisher
public event NumberChanged NumberChanged;
/* Other methods and members */
Suppose the class MySubscriber wants to subscribe to the event in the class constructor. When you type the += operator to assign into a delegate, IntelliSense will preset a ToolTip offering to add a new delegate of a matching type by pressing the Tab key. If you do not like the default target method name you can simply type a different method name in its place. If the target method does not exist, IntelliSense will offer to generate a handling method by that name by pressing the Tab key once more. This sequence is presented in Figure 3. This IntelliSense support only works with delegates defined as events (not mere delegates). Also worth mentioning is that there is no IntelliSense support for removing a subscription:
public void UnSubscribe()
//This has no IntelliSense support:
publisher.NumberChanged -= new