ある課題で、デリゲートを使用して 4 つの基本的な数学関数を一度に実行するプログラムを作成することになっていました。私がしたこと。これがそのコードです。
Module Module1
Public Delegate Sub math(ByVal A As Integer, ByVal B As Integer)
Dim A, B, C As Integer
Sub Main()
Console.WriteLine("Please enter a number")
A = Int32.Parse(Console.ReadLine())
Console.WriteLine("Please enter another number")
B = Int32.Parse(Console.ReadLine())
Dim objmath As New math(AddressOf add)
objmath(A, B)
add(A, B)
objmath = New math(AddressOf multiply)
objmath(A, B)
multiply(A, B)
objmath = New math(AddressOf subtract)
subtract(A, B)
subtract(A, B)
objmath = New math(AddressOf divide)
divide(A, B)
divide(A, B)
Console.ReadKey()
End Sub
Sub add(ByVal A As Integer, ByVal B As Integer)
C = A + B
Console.WriteLine(C)
End Sub
Sub multiply(ByVal A As Integer, ByVal B As Integer)
C = A * B
Console.WriteLine(C)
End Sub
Sub subtract(ByVal A As Integer, ByVal B As Integer)
C = A - B
Console.WriteLine(C)
End Sub
Sub divide(ByVal A As Integer, ByVal B As Integer)
C = A / B
Console.WriteLine(C)
End Sub
End Module
ここで、4 つのプロシージャすべてを保持し、DynamicInvoke() メソッドを使用してプロシージャを呼び出すマルチキャスト デリゲートをこのプログラムに追加するように依頼されました。プログラムのどこにどのように追加しますか?