Delegate Manipulation using VB.NET

we can reference multiple delegates by referencing one delegate
  • 1975

VB.NET Framework use  a function pointer in the form of type safe. we specify a method and object in delegates to call the method. you use instances of the delegate as the reference to the another delegate. Hence we can reference multiple delegates by referencing one delegate. If the chain Reference is not null the delegates invoked one by one till the list is complete.

You can learn delegate manipulation by studying this code:

Example

    Module Module1
        Public Class del
            Public Delegate Function simpleDelegate(ByVal a As Integer, ByVal b As Integer) As Integer
                Public
Function multiplynumber(ByVal a As Integer, ByVal b As Integer) As Integer
                Return
(a * b)
            End Function
            Public
Function subtractnumber(ByVal a As Integer, ByVal b As Integer) As Integer
                Return
(a - b)
            End Function
            Public
Shared Sub Main()
                Dim obj As New del
                Dim addDelegate As New simpleDelegate(AddressOf obj.multiplynumber)
                Dim mulDelegate As New simpleDelegate(AddressOf obj.subtractnumber)
                Dim multiply As Integer = addDelegate(23, 43)
                Dim subtract As Integer = mulDelegate(20, 9)
                Console.WriteLine("Result by first delegate: {0}", multiply)
                Console.WriteLine("Result by second delegate: {0}", subtract)
                Console.ReadLine()
            End Sub
        End
Class
    End
Module

Output

5.gif
 

CONCLUSION

This article helps you to understand about the declaration and implementation of delegates in Vb.Net

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.