VB.net Program to Call Multiple Methods Using a Single-Cast Delegate

You are currently viewing VB.net Program to Call Multiple Methods Using a Single-Cast Delegate

VB.Net program to call multiple methods using a single-cast delegate

'VB.net program to handle multiple methods 
'using single caste delegate.

Public Delegate Sub MyDelegate(ByVal num1 As Integer, ByVal num2 As Integer)
Class CalC
    Public Sub Addition(ByVal num1 As Integer, ByVal num2 As Integer)
        Dim result As Integer
        result = num1 + num2
        Console.WriteLine("Addition is: {0}", result)

    End Sub

    Public Sub Subtraction(ByVal num1 As Integer, ByVal num2 As Integer)
        Dim result As Integer
        result = num1 - num2
        Console.WriteLine("Subtraction is: {0}", result)
    End Sub
End Class 

Module Module1
    Sub Main()
        Dim cal As New CalC()

        Dim del As MyDelegate = AddressOf cal.Addition
        del(20, 10)

        del = AddressOf cal.Subtraction
        del(20, 10)
    End Sub
End Module
Addition is: 30
Subtraction is: 10
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply