gpt4 book ai didi

vb.net - 添加一个包含所有四个数学过程的多播委托(delegate)?

转载 作者:行者123 更新时间:2023-12-02 06:49:16 27 4
gpt4 key购买 nike

我必须为我的编程课编写如下所示的小型 vb.net 控制台程序。现在我必须这样做:

Add a multicast delegate that holds all four procedures. Call the procedures using the DynamicInvoke() method.

我该怎么做?我尝试了我能想到的一切,但似乎无法弄清楚。这是我的代码。随意做任何你想做的事。任何帮助和解释表示赞赏。谢谢!

Imports System
Module Module1
Dim a, b, result as Integer
Private Delegate Sub myDelegate()
Sub Main()
Dim ask As myDelegate
ask = New myDelegate(AddressOf Ask1)
ask()
Dim Multiply1 As myDelegate
Multiply1 = New myDelegate(AddressOf Multiply)
Multiply1()
Dim Subtraction1 As myDelegate
Subtraction1 = New myDelegate(AddressOf Subtraction)
Subtraction1()
Dim Addition1 As myDelegate
Addition1 = New myDelegate(AddressOf Addition)
Addition1()
Dim Division1 As myDelegate
Division1 = New myDelegate(AddressOf Division)
Division1()
Console.ReadLine()
End Sub
Sub Ask1()
Console.WriteLine("Enter First Number")
a = Console.ReadLine()
Console.WriteLine("Enter Second Number")
b = Console.ReadLine()
End Sub
Sub Addition()
Result = a + b
Console.WriteLine("Added: " & Result)
End Sub
Sub Subtraction()
Result = a - b
Console.WriteLine("Subtracted: " & Result)
End Sub
Sub Multiply()
result = a * b
Console.WriteLine("Multiplied: " & Result)
End Sub
Sub Division()
Console.WriteLine("Divided: " & a / b)
End Sub
End Module

最佳答案

有这样的事吗? ...将其添加到 Main 末尾:

    Dim dMultiCast As myDelegate
dMultiCast = [Delegate].Combine(New myDelegate(AddressOf Addition),
New myDelegate(AddressOf Subtraction),
New myDelegate(AddressOf Division),
New myDelegate(AddressOf Multiply))
dMultiCast.DynamicInvoke()

Console.ReadLine()
End Sub

关于vb.net - 添加一个包含所有四个数学过程的多播委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14543045/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com