有没有办法在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();
}
答案 0 :(得分:4)
不确定。您可以创建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