将多播委托添加到VB.NET程序

时间:2014-05-02 20:06:51

标签: 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(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()方法调用这些过程。如何以及在我的程序中添加它?

0 个答案:

没有答案