|
62 | 62 | <format type="text/markdown"><![CDATA[
|
63 | 63 |
|
64 | 64 | ## Remarks
|
65 |
| - You can use this delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have no parameters and no return value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. |
| 65 | + You can use this delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have no parameters and no return value. (In C#, the method must return `void`. In F# the function or method must return `unit`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. |
66 | 66 |
|
67 | 67 | > [!NOTE]
|
68 | 68 | > To reference a method that has no parameters and returns a value, use the generic <xref:System.Func%601> delegate instead.
|
|
71 | 71 |
|
72 | 72 | :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.action.delegate/cpp/delegate.cpp" id="Snippet1":::
|
73 | 73 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.action.delegate/cs/delegate.cs" id="Snippet1":::
|
| 74 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Delegate.fs" id="Snippet1"::: |
74 | 75 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.action.delegate/vb/delegate.vb" id="Snippet1":::
|
75 | 76 |
|
76 | 77 | The following example simplifies this code by instantiating the <xref:System.Action> delegate instead of explicitly defining a new delegate and assigning a named method to it.
|
77 | 78 |
|
78 | 79 | :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Action/cpp/action.cpp" id="Snippet2":::
|
79 | 80 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Action/cs/Action.cs" id="Snippet2":::
|
| 81 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Action.fs" id="Snippet2"::: |
80 | 82 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Action/vb/Action.vb" id="Snippet2":::
|
81 | 83 |
|
82 | 84 | You can also use the <xref:System.Action> 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).)
|
83 | 85 |
|
84 | 86 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Action/cs/Anon.cs" id="Snippet3":::
|
85 | 87 |
|
86 |
| - You can also assign a lambda expression to an <xref:System.Action> delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions).) |
| 88 | + You can also assign a lambda expression to an <xref:System.Action> delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) |
87 | 89 |
|
88 | 90 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Action/cs/Lambda.cs" id="Snippet4":::
|
| 91 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Lambda.fs" id="Snippet4"::: |
89 | 92 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Action/vb/lambda.vb" id="Snippet4":::
|
90 | 93 |
|
91 | 94 | ]]></format>
|
|
0 commit comments