Multiple Delegates : Delegate « Class Module « VB.Net Tutorial






Module Module1

    Delegate Sub NotifyInfo()
    Dim ListOfDelegates(3) As NotifyInfo

    Sub Testing()
        Console.WriteLine("AAA")
    End Sub

    Sub Coding()
        Console.WriteLine("BBB")
    End Sub

    Sub Meeting()
        Console.WriteLine("CCC")
    End Sub

    Sub Main()
        ListOfDelegates(0) = New NotifyInfo(AddressOf Coding)
        ListOfDelegates(1) = New NotifyInfo(AddressOf Testing)
        ListOfDelegates(2) = New NotifyInfo(AddressOf Meeting)

        Dim NotifyAll As New NotifyInfo(AddressOf Coding)
        NotifyAll = NotifyInfo.Combine(ListOfDelegates)

        NotifyAll.Invoke()
    End Sub

End Module
BBB
AAA
CCC








6.28.Delegate
6.28.1.Define delegate
6.28.2.Define a delegate to be a pointer to a subroutine that has a string parameter.
6.28.3.Use Delegate Sub
6.28.4.Delegate Function
6.28.5.Uses delegates to sort random numbers (ascending or descending)
6.28.6.Use AddressOf to assign function to a delegate
6.28.7.Comparison method based on delegate
6.28.8.Multiple Delegates
6.28.9.Math delegation
6.28.10.Use one Delegate to reference two different functions
6.28.11.Reference a method that has one parameter and returns a value: Func<(Of <(T, TResult>)>)