有没有办法将函数的引用添加到 VB.NET 中的列表或数组?在 JavaScript 中是这样的:
function hello() {
console.log('hello, world!');
}
function test() {
console.log('test');
}
var functionList = [];
functionList.push(hello);
functionList.push(test);
functionList.forEach(function(n) {
n();
}
Run Code Online (Sandbox Code Playgroud)
当然。您可以创建一个Action委托列表:
Sub Hello()
Console.WriteLine("hello, world!")
End Sub
Sub Test()
Console.WriteLine("test")
End Sub
Sub Main()
Dim functionList As List(Of Action) = New List(Of Action)()
functionList.Add(AddressOf Hello)
functionList.Add(AddressOf Test)
For Each n As Action In functionList
n()
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |