Wednesday, August 11, 2004

Asp.net:Delegates and events


Asp.net:Delegates and events










NET, defines a delegate as a class that holds a reference to a method
oEssentially a typesafe callback method reference (pointer)


In Vb.NET you can define delegate as
Public
Delegate Sub MyCallbackHandler(x as integer)


The signature of the
delegate defines the signature of the methods it can call. For example, the
MyCallbackHandler delegate shown above can be used to refer to void methods that
take a single integer as a parameter:





and Events are declared as
Public Event
MyCallbackEvent As MyCallbackHandler


Events can be used to inform an object that
something significant has happened, and interrupt the flow of control in that
object causing it to execute a method designed for handling the event. An event
provides a component with a hook that an interested client can attach one of its
methods to. When the component wants to indicate that something significant has
happened, it can raise the event and consequently call the associated
methods


Events are closely related to delegates, and rely
on the functionality of multicast delegates for registering methods to be called
when an event is raised






Regards,
Mitesh v. Mehta



No comments: