Delegates in VB.NET
In this article we will discuss about the Delegates functionality.
Delegates play an important roll in the
programming model of the .NET framework. They provide valuable support for
developers who need to design and write software that use the callback
notification. for example Event-handling is based on Callback.
Application software often designed around the programming technique known
as Callback. In a callback, one part of an application sends out notification to
alert other parts of an application when something interesting has occurred.
More specifically, a callback is call from a notification source back to method
implemented by one or more handlers.
Definition of Delegates:
Delegates is nothing but, it is work as a function pointer.
In Visual Basic .NET, you define a delegate type by using the Delegate
key word each delegate definition you create must include a type name and
calling signature for handler method.
'Deligate without parameters
'Deligate with parameters
Note: There are various points to remember during delegates declaration
- Delegate can not use as a Private
- Out parameter is not allowed in Delegate.
- Delegate type must be defined using either
the sub keyword or the function keyword.
Creating Delegate Object:-When you want
to create a delegate object, you typically use
the new operator followed by the name of the delegate type.
Handler1 As delegatename1
Note: There are various points to
remember during delegates object creation
- Handler1 is not an object, it is a
reference Id variable that can hold all reference id.
- Before you can create delegate object, you
must determine the handler method to
which it should bind. A handler method can be either a shared or an instance
Coding for Delegates:
Class Chal :
Dim obj As
Dim obj1 As
Dim obj2 As
obj1 = New Display(AddressOf
obj2 = New Display(AddressOf
of Delegates:-There are various Advantages of delegates
Delegates provide one of
the easiest ways to become involved in multithreading.
Delegates are useful to
use the event handling.
delegates are also useful
to window forms and asp.net.