Func(TResult) Delegate represents a method with no parameters returning a value of the type specified by the TResult parameter.
Imports System.IO
Delegate Function WriteMethod As Boolean
Module TestDelegate
Public Sub Main()
Dim output As New OutputTarget()
Dim methodCall As WriteMethod = AddressOf output.SendToFile
If methodCall() Then
Console.WriteLine("Success!")
End If
End Sub
End Module
Public Class OutputTarget
Public Function SendToFile() As Boolean
Try
Dim fn As String = Path.GetTempFileName
Dim sw As StreamWriter = New StreamWriter(fn)
sw.WriteLine("Hello, World!")
sw.Close
Return True
Catch
Return False
End Try
End Function
End Class
Related examples in the same category