Declare a Func variable and assign a lambda expression to the variable : Lambda « Language Basics « VB.Net






Declare a Func variable and assign a lambda expression to the variable

 

Imports System.Collections.Generic
Imports System.Linq

Module Func
   Public Sub Main()

      Dim selector As Func(Of String, String) = Function(str) str.ToUpper()

      Dim words() As String = { "A", "B", "C", "D" }
      Dim aWords As IEnumerable(Of String) = words.Select(selector)

      For Each word As String In aWords
         Console.WriteLine(word)
      Next
   End Sub
End Module

   
  








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.Predicate(T) Delegate represents the method that defines a set of criteria
5.Converter(TInput, TOutput) Delegate represents a method that converts an object from one type to another type.
6.Func(TResult) Delegate represents a method with no parameters returning a value of the type specified by the TResult parameter.