0

For an assignment I was supposed to write a program that used delegates to do all four basic math functions at once. Which I did. Here is the code from that.

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

Now I have been asked to add a multicast delegate to this program that holds all four procedures and calls the procedures using the DynamicInvoke() method. How and where in my program would I add that?

  • We're not here to do your homework. *YOU* do it. Show us some effort before you ask for help. – Sam Axe May 02 '14 at 20:08
  • This is not homework. This is my work that I have done so far. My curriculum did not explain delegates very well and didn't explain multi-cast delegates at all. I am not asking for the answer, just clarifications and some examples with explanations. I am here to learn. – Tim The Learner May 02 '14 at 20:11
  • Students that attend your school have asked this question several times already. There's [one here](http://stackoverflow.com/questions/20712319/multicast-delegates-not-defined-error/20712415#20712415) for example. – Hans Passant May 02 '14 at 20:20

0 Answers0