Events and delegates

Delegate and Event concepts are completely tied together. Even if they were exactly the same thing there will still remain the semantical difference. Delegates is a function pointer which can able to store the address of any function with same prototype. While Event is a function handler which can handles or run the functions in same prototype of its delegate.

A delegate is a more generic term to describe a construct similar to a pointer in C/C++ terms. It holds a reference to a method and to an object instance (if the method is non-static). All delegates in .Net are multicast delegates i.e. they hold references to several object/method pairs. Conceptually we can considered it as function templates; that is, they express a contract a function must adhere to in order to be considered of the "type" of the delegate.

An event is just a wrapper for a multicast delegate. An Event declaration adds a layer of abstraction and protection on the delegate instance. Adding a public event to a class is almost the same as adding a public multicast delegate field. In both cases, subscriber objects can register for notifications, and in both cases the publisher object can send notifications to the subscribers.

What is .Net Delegates

In the .NET environment, a delegate is a type that defines a method signature and it can pass a function as a parameter. In simple words we can say delegate is a .NET object which points to a method that matches its specific signature. More details about... .Net Delegates
 (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About