Delegates: - It is a procedure pointer, which stores the memory address of another procedure. It can be applied with
1.Sub procedure
2.Function procedure
But not property procedure.
Program
Ex1
Public Class
Form1
Delegate Sub abhisek(ByVal x As Integer, ByVal y As Integer)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
Button1.Click
Dim a As abhisek
a = AddressOf rajiv
a.Invoke(10, 20)
End Sub
Public Sub
rajiv(ByVal x As
Integer, ByVal
y As Integer)
Dim z As Integer
z = x + y
MsgBox(z)
End Sub
End
Class
Ex2
Public Class
Form2
Delegate Sub raj(ByVal x As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
Button1.Click
Dim x As raj
x = AddressOf rajiv
x.Invoke("Adarsh
kumar")
End Sub
Private Sub rajiv(ByVal s As String)
MsgBox("Hello:"
& s)
End Sub
End Class

Comments
Join the conversation! Your thoughts help the community grow.