|
79 | 79 |
|
80 | 80 | The following example simplifies this code by instantiating the <xref:System.Func%602> delegate instead of explicitly defining a new delegate and assigning a named method to it.
|
81 | 81 |
|
82 |
| - [!code-csharp[System.Func~2#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Func2_1.cs#2)] |
| 82 | + [!code-csharp-interactive[System.Func~2#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Func2_1.cs#2)] |
83 | 83 | [!code-vb[System.Func~2#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Func2_1.vb#2)]
|
84 | 84 |
|
85 | 85 | You can also use the <xref:System.Func%602> delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](~/docs/csharp/programming-guide/statements-expressions-operators/anonymous-methods.md).)
|
86 | 86 |
|
87 |
| - [!code-csharp[System.Func~2#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Anon.cs#3)] |
| 87 | + [!code-csharp-interactive[System.Func~2#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Anon.cs#3)] |
88 | 88 |
|
89 | 89 | You can also assign a lambda expression to a <xref:System.Func%602> delegate, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions](~/docs/visual-basic/programming-guide/language-features/procedures/lambda-expressions.md) and [Lambda Expressions](~/docs/csharp/programming-guide/statements-expressions-operators/lambda-expressions.md).)
|
90 | 90 |
|
91 |
| - [!code-csharp[System.Func~2#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Lambda.cs#4)] |
| 91 | + [!code-csharp-interactive[System.Func~2#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Lambda.cs#4)] |
92 | 92 | [!code-vb[System.Func~2#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Lambda.vb#4)]
|
93 | 93 |
|
94 | 94 | The underlying type of a lambda expression is one of the generic `Func` delegates. This makes it possible to pass a lambda expression as a parameter without explicitly assigning it to a delegate. In particular, because many methods of types in the <xref:System.Linq> namespace have <xref:System.Func%602> parameters, you can pass these methods a lambda expression without explicitly instantiating a <xref:System.Func%602> delegate.
|
|
97 | 97 |
|
98 | 98 | ## Examples
|
99 | 99 | The following example demonstrates how to declare and use a <xref:System.Func%602> delegate. This example declares a <xref:System.Func%602> variable and assigns it a lambda expression that converts the characters in a string to uppercase. The delegate that encapsulates this method is subsequently passed to the <xref:System.Linq.Enumerable.Select%2A?displayProperty=nameWithType> method to change the strings in an array of strings to uppercase.
|
100 |
| - |
101 |
| - [!code-csharp[System.Func~2#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Example.cs#5)] |
| 100 | +
|
| 101 | + [!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)] |
| 102 | +
|
| 103 | + [!code-csharp-interactive[System.Func~2#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Example.cs#5)] |
102 | 104 | [!code-vb[System.Func~2#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Example.vb#5)]
|
103 | 105 |
|
104 | 106 | ]]></format>
|
|
0 commit comments