Posted by: Sourav | August 21, 2016

Multicast Delegate Example in VB,VB Teacher Sourav


Option Strict On
Option Explicit On
Imports System
Delegate Sub sampledelegate()
Delegate Function sampdelegate(ByVal x As Integer, ByVal y As Integer) As Integer
Module Module1

Sub Main()
Dim del1, del2, del3, del4 As sampledelegate
del1 = New sampledelegate(AddressOf samplemethod1)
del2 = New sampledelegate(AddressOf samplemethod2)
del3 = New sampledelegate(AddressOf samplemethod3)
del4 = CType(System.Delegate.Combine(del1, del2, del3), sampledelegate)
del4 = CType(System.Delegate.Remove(del4, del3), sampledelegate)
del4()

Console.ReadLine()

End Sub

Sub samplemethod1()
Console.WriteLine(“samplemethod1 invoked”)

End Sub
Sub samplemethod2()
Console.WriteLine(“samplemethod2 invoked”)

End Sub
Sub samplemethod3()
Console.WriteLine(“samplemethod3 invoked”)

End Sub

Function f1(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y

End Function

Function f2(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y

End Function

End Module

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: