Func(TResult) Delegate represents a method with no parameters returning a value of the type specified by the TResult parameter. : Lambda « Language Basics « VB.Net






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

1.Func(T, TResult) represents a method that has one parameter and returns one value
2.Instantiate delegate to reference method
3.Lambda Expression and Function
4.Declare a Func variable and assign a lambda expression to the variable
5.Predicate(T) Delegate represents the method that defines a set of criteria
6.Converter(TInput, TOutput) Delegate represents a method that converts an object from one type to another type.