This paper analyzes the difference between action and Func in C #, which can help the reader to grasp and use it accurately. The specific analysis is as follows:
First look at the following code:
The test uses the common value int num = 10;//Test func delegate func<int, int> f;f = (int Tempf) + = {return Tempf + 1;}; Response.Write (f (NUM). ToString () + "<br/>"); Call the F delegate and print the corresponding value! Test the action delegate action<int> a;a = (int Tempa) + {Response.Write (string. Format ("I can't return a value, so I can only output here!" Your input parameters are: {0} ", Tempa)); };a (num); Call a Delegate method
Main differences:
Func<t, Result> encapsulates a method that has a parameter and returns the type value specified by the TResult parameter
。
Action<t> encapsulates a method that takes only one parameter and does not return a value
。
I hope this article is helpful to the study of C # program design.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
The difference between action and Func in C #
This address: http://www.paobuke.com/develop/c-develop/pbk23562.html
Related content C # to implement additions and deletions of XML documents example C # method of exporting DataTable to HTML format Analysis C # static class, static constructor, static variable understanding C # Generation Verification code process
In-depth parsing of struct-defined structures in C # programming C # Implementation of 3-Step manual DataGridView Method C # Connecting ODBC data sources part of the application in C # functional programming
The difference between action and Func in C #