How to pass a runnable procedure (a function) as a parameter and run it in VB.NET

2 Answers

0 votes
Imports System

Class Program
    Delegate Sub FuncDelegate()

    Private Shared Sub Control(ByVal f As FuncDelegate)
        f()
    End Sub

	Private Shared Sub Say()
        Console.WriteLine("abcd")
    End Sub

    Public Shared Sub Main()
        Control(AddressOf Say)
    End Sub
End Class

 
 
' run:
'
' abcd
'

 



answered May 21, 2025 by avibootz
0 votes
Imports System

Class Program
    Private Shared Function Control(Of T)(ByVal f As Func(Of T)) As T
        Return f()
    End Function

    Private Shared Function say() As String
        Return "abcd"
    End Function

	Public Shared Sub Main()
        Console.WriteLine(Control(AddressOf say))
    End Sub
End Class


 
 
' run:
'
' abcd
'

 



answered May 21, 2025 by avibootz
...