Combining Delegates: Multicast Delegates
A delegate can hold a reference (that is, the address) to a method. It is possible to create delegates holding references to more than one method by creating multicast delegates. A multicast delegate is the combination of two or more delegates into a single delegate, providing the delegate the capability to make multiple invocations. The following code demonstrates how to create a multicast delegate, having two instances of the same delegate pointing to two different methods:
'The delegate is defined at namespace levelPublic Delegate Sub WriteTextMessage(ByVal textMessage As String)'....Private textWriter As New WriteTextMessage(AddressOf WriteSomething)Private complexWriter ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.