|
91 | 91 | When you use the <xref:System.Func%602> delegate, you do not have to explicitly define a delegate that encapsulates a method with a single parameter. For example, the following code explicitly declares a delegate named `ConvertMethod` and assigns a reference to the `UppercaseString` method to its delegate instance. |
92 | 92 | |
93 | 93 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: |
| 94 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Delegate.fs" id="Snippet1"::: |
94 | 95 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Delegate.vb" id="Snippet1"::: |
95 | 96 | |
96 | 97 | 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. |
97 | 98 | |
98 | 99 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Func2_1.cs" interactive="try-dotnet-method" id="Snippet2"::: |
| 100 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Func2_1.fs" id="Snippet2"::: |
99 | 101 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Func2_1.vb" id="Snippet2"::: |
100 | 102 | |
101 | 103 | 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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) |
102 | 104 | |
103 | 105 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Anon.cs" interactive="try-dotnet-method" id="Snippet3"::: |
104 | 106 | |
105 | | - 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](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions) and [Lambda Expressions](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions).) |
| 107 | + 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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) |
106 | 108 | |
107 | 109 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Lambda.cs" interactive="try-dotnet-method" id="Snippet4"::: |
| 110 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Lambda.fs" id="Snippet4"::: |
108 | 111 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Lambda.vb" id="Snippet4"::: |
109 | 112 | |
110 | 113 | 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. |
|
115 | 118 | 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. |
116 | 119 |
|
117 | 120 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Example.cs" interactive="try-dotnet-method" id="Snippet5"::: |
| 121 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Example.fs" id="Snippet5"::: |
118 | 122 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Example.vb" id="Snippet5"::: |
119 | 123 | :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Func~2/cpp/Example.cpp" id="Snippet6"::: |
120 | 124 | |
121 | 125 | ]]></format> |
122 | 126 | </remarks> |
123 | 127 | <related type="Article" href="/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions">Lambda Expressions (C# Programming Guide)</related> |
| 128 | + <related type="Article" href="/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword">Lambda Expressions: The fun Keyword (F#)</related> |
124 | 129 | <related type="Article" href="/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions">Lambda Expressions (Visual Basic)</related> |
125 | 130 | <related type="Article" href="/dotnet/csharp/programming-guide/delegates/">Delegates (C# Programming Guide)</related> |
| 131 | + <related type="Article" href="/dotnet/fsharp/language-reference/delegates/">Delegates (F#)</related> |
126 | 132 | <related type="Article" href="/dotnet/visual-basic/programming-guide/language-features/delegates/">Delegates (Visual Basic)</related> |
127 | 133 | </Docs> |
128 | 134 | </Type> |
0 commit comments