Last active 1704332767

Example of an Action/Func in C#

Revision a75986e5eec7eacf7257e49bd803309a5295fe39

Action.cs Raw
1using System;
2using System.Windows.Forms;
3
4public class TestLambdaExpression
5{
6 public static void Main()
7 {
8 Action<string> messageTarget;
9
10 if (Environment.GetCommandLineArgs().Length > 1)
11 messageTarget = s => ShowWindowsMessage(s);
12 else
13 messageTarget = s => Console.WriteLine(s);
14
15 messageTarget("Hello, World!");
16 }
17
18 private static void ShowWindowsMessage(string message)
19 {
20 MessageBox.Show(message);
21 }
22}