Delegate Action, Func, and Predicate are many predefined Delegate types used during development. All three are located under the System namespace Of the. Net class library. This article will give a brief introduction to the Action delegate among the three,
Hope to help those who are interested in it.
Description (required): here, the Action delegate refers to a type of Delegate with the Action keyword contained in the delegate definition. We know that such a type of delegation includes: "Action delegate" (for fear of confusion with you), "Action <T>
"Delegate", "Action <T, T> delegate", etc. Unless otherwise stated in this article, "Action delegate" refers to "actions such delegate" (a little troublesome, however, I cannot find a good expression. Sorry ).
Before defining an Action delegate, let's look at a simple example of an Action delegate.
The Code is as follows:
Action<string> printAction = delegate(string printString) { Console.WriteLine(printString); }; printAction("Hello World!"); Action<string> printAction = delegate(string printString){ Console.WriteLine(printString);};printAction("Hello World!");<SPAN style="BACKGROUND: rgb(255,255,255); COLOR: #000000"></SPAN>
The above code first creates the delegate instance printAction of the delegate Action <string> using the anonymous method, and then calls the delegate instance printAction to output the string "Hello World! ".
Here we insert a few words: I don't know how you understand the delegation.
My personal understanding of delegation at this stage is that the delegate type is accurate. You can use this type to create the corresponding delegate instance, and finally call the created delegated instance to complete the operation. The delegate type defines only one method interface.
The delegated instance can be seen as an object that implements that interface.