The difference between action and Func in C #

Source: Internet
Author: User

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 #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.