Action<> and func<> in C #

Source: Internet
Author: User

In fact, both of them are the abbreviated form of "agent" entrusted.

First, "action<>" specifies that only input parameters, no return value of the delegate

Delegate's Code:

[CSharp]View Plaincopy
    1. public delegate  void mydelegate (string str);   
    2. public static void hellowchinese (string strchinese)   
    3. {&NBSP;&NBSP;
    4.     console.writeline (
    5.      console.readline ();   
    6. }  
    7. &NBSP;&NBSP;
    8. Mydelegate d = new mydelegate (hellowchinese);   
    9. d (


After using the action:

[CSharp]View Plaincopy
    1. Public static void Hellowchinese (string strchinese)
    2. {
    3. Console.WriteLine ("Good morning," + Strchinese);
    4. Console.ReadLine ();
    5. }
    6. action<string> action = Hellowchinese;
    7. Action ("Spring.");

is tantamount to omitting the steps to define a delegate.

Second, func<> this and the above is the same, the difference is that there is a return value!

[CSharp]View Plaincopy
      1. Public static string Helloenglish (string strenglish)
      2. {
      3. return "Hello." + strenglish;
      4. }
      5. func<String, string> f = helloenglish;
      6. Console.WriteLine (f ("Srping ji"));
      7. Console.ReadLine ();

Action<> and Func<> in C #;

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.