1

我有当前代码,可以使用委托打印输入数字的数学结果。

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

我需要添加一个包含所有四个过程的多播委托,并使用 DynamicInvoke() 方法调用这些过程。

4

0 回答 0