Assign a lambda expression to an Action<(Of <(T>)>) delegate instance : Lambda « LINQ « VB.Net Tutorial






Imports System.Windows.Forms

Public Module TestLambdaExpression
   Public Sub Main()
      Dim messageTarget As Action(Of String) 

      If Environment.GetCommandLineArgs().Length > 1 Then
         messageTarget = Function(s) ShowWindowsMessage(s) 
      Else
         messageTarget = Function(s) ShowConsoleMessage(s)
      End If
      messageTarget("Hello, World!")
   End Sub

   Private Function ShowWindowsMessage(message As String) As Integer
      Return MessageBox.Show(message)      
   End Function

   Private Function ShowConsoleMessage(message As String) As Integer
      Console.WriteLine(message)
      Return 0
   End Function
End Module








12.1.Lambda
12.1.1.Lambda Functions for Str.Reverse()
12.1.2.Assign a lambda expression to an Action<(Of <(T>)>) delegate instance