将多播委托添加到VB.NET程序
对于一项作业,我应该编写一个程序,使用代理同时完成所有四个基本数学函数。我做到了。这是它的代码将多播委托添加到VB.NET程序,vb.net,math,delegates,console-application,multicastdelegate,Vb.net,Math,Delegates,Console Application,Multicastdelegate,对于一项作业,我应该编写一个程序,使用代理同时完成所有四个基本数学函数。我做到了。这是它的代码 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(C
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
现在,我被要求向这个程序添加一个多播委托,它包含所有四个过程,并使用DynamicInvoke()方法调用这些过程。在我的程序中,我将如何以及在哪里添加这些内容?我们不是来给你做作业的。你做到了。在你寻求帮助之前,给我们一些努力。这不是家庭作业。这是我迄今为止所做的工作。我的课程没有很好地解释代表,也没有解释多演员代表。我不是问答案,只是澄清和一些例子的解释。我是来学习的。你们学校的学生已经问过好几次这个问题了。举个例子。