Mega Code Archive

 
Categories / VB.Net Tutorial / Class Module
 

Use one Delegate to reference two different functions

Imports System   Module HelloWorld     Delegate Sub MyDelegate(ByVal msg as String)     Public Sub Main()       Dim msg As String = "Hello Delegates"       Dim d1 as MyDelegate = AddressOf PrintOnce       Dim d2 as MyDelegate = AddressOf PrintTwice       d1(msg)       d2(msg)     End Sub     Public Sub PrintOnce(ByVal msg as String)       Console.WriteLine(msg)     End Sub     Public Sub PrintTwice(ByVal msg as String)       Console.WriteLine("1." & msg)       Console.WriteLine("2." & msg)     End Sub   End Module