Mega Code Archive

 
Categories / VB.Net / Language Basics
 

Function Delegate

Imports System Public Class MainClass     ' delegate to be a pointer to a subroutine     ' that has a string parameter.     Private Delegate Sub StringDisplayerType(ByVal str As String)     Shared Sub Main(ByVal args As String())         Dim m_DisplayStringRoutine As StringDisplayerType         ' Assign the variable to a subroutine.         m_DisplayStringRoutine = AddressOf ShowStringInMessageBox          ' Invoke the delegate's subroutine.         m_DisplayStringRoutine("Hello world")                  m_DisplayStringRoutine = AddressOf ShowStringInOutputWindow         ' Invoke the delegate's subroutine.         m_DisplayStringRoutine("Hello world")              End Sub     Shared Private Sub ShowStringInOutputWindow(ByVal str As String)         Console.WriteLine(str)     End Sub     Shared Private Sub ShowStringInMessageBox(ByVal str As String)         Console.WriteLine(str)     End Sub End Class