Func.cs(файл создан)
@@ -0,0 +1,11 @@ | |||
1 | + | Func<string, string> convert = delegate(string s) | |
2 | + | { | |
3 | + | return s.ToUpper(); | |
4 | + | }; | |
5 | + | ||
6 | + | string name = "Dakota"; | |
7 | + | Console.WriteLine(convert(name)); | |
8 | + | ||
9 | + | // This code example produces the following output: | |
10 | + | // | |
11 | + | // DAKOTA |
Action.cs(файл создан)
@@ -0,0 +1,22 @@ | |||
1 | + | using System; | |
2 | + | using System.Windows.Forms; | |
3 | + | ||
4 | + | public 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 | + | } |
Новее
Позже