I have the current code that will print mathematical results of input numbers using delegates.
Imports System.Delegate
Module Module1
Dim a As Decimal
Dim b As Decimal
Dim Answer As Integer
Private Delegate Sub myDelegate()
Sub Main()
Dim question As myDelegate
question = New myDelegate(AddressOf Question1)
question()
Dim Multiplication1 As myDelegate
Multiplication1 = New myDelegate(AddressOf Multiplication)
Multiplication1()
Dim Subtract1 As myDelegate
Subtract1 = New myDelegate(AddressOf Subtract)
Subtract1()
Dim Addition1 As myDelegate
Addition1 = New myDelegate(AddressOf Addition)
Addition1()
Dim Divide1 As myDelegate
Divide1 = New myDelegate(AddressOf Divide)
Divide1()
Console.ReadLine()
Dim DoAll As [Delegate]
DoAll = [Delegate].Combine(Multiplication1, Subtract1, Addition1, Divide1)
DoAll.DynamicInvoke(3, 5)
End Sub
Sub Question1()
Console.WriteLine("Enter First Number")
a = Console.ReadLine()
Console.WriteLine("Enter Second Number")
b = Console.ReadLine()
End Sub
Sub Multiplication()
Answer = a * b
Console.WriteLine("The Answer for multiplication is " & Answer)
End Sub
Sub Subtract()
Answer = a - b
Console.WriteLine("The Answer for subtraction is " & Answer)
End Sub
Sub Addition()
Answer = a + b
Console.WriteLine("The Answer for addition is " & Answer)
End Sub
Sub Divide()
Answer = a / b
Console.WriteLine("The Answer for division is " & Answer)
End Sub
End Module
I need to Add a multicast delegate that holds all four procedures and Call the procedures using the DynamicInvoke() method.