Assign a lambda expression to an Action<(Of <(T>)>) delegate instance : Action « Development « C# / CSharp Tutorial






using System;
using System.Windows.Forms;

public class TestLambdaExpression
{
   public static void Main()
   {
      Action<string> messageTarget; 

      if (Environment.GetCommandLineArgs().Length > 1)
         messageTarget = s => ShowWindowsMessage(s); 
      else
         messageTarget = s => Console.WriteLine(s);

      messageTarget("Hello, World!");
   }

   private static void ShowWindowsMessage(string message)
   {
      MessageBox.Show(message);      
   }
}








14.41.Action
14.41.1.Instantiating Action<(Of <(T>)>) delegate rather than defining a new delegate
14.41.2.Use Action<(Of <(T>)>) delegate with anonymous methods
14.41.3.Assign a lambda expression to an Action<(Of <(T>)>) delegate instance