Reputation: 997
Is there a way to add references to functions to a list or array in VB.NET? Something like this in 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();
}
Upvotes: 4
Views: 125
Reputation: 36483
Sure. You can create a list of Action delegates:
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
Upvotes: 5