C # generic Delegate Action/func

Source: Internet
Author: User

A generic delegate is actually a predefined delegate of the. NET framework that basically covers all the commonly used delegates, so it is generally not necessary for users to declare them again. simple and convenient .


' 1 generic delegate with no return value


The Action series generic delegate is a delegate that has no return parameter, and the call is not declared as a normal delegate.


Example:

            Action test1 = () => {Console.WriteLine ("Void Method ();");
            Action<int, double> test2 = (int x, double y) => {Console.WriteLine ("Void Method (T1, T2)");

            Test1 ();
            Test2 (2, 3);


"2" has a generic delegate with a return value


Func Series Generic delegate, is a delegate with a return value, and the last parameter represents a return parameter.


Example:

            func<int> test3 = () => {return (a);};
            Func<double, int> test4 = (double x) => {return (int) (x * 2);

            Console.WriteLine (Test3 ());
            Console.WriteLine (Test4 (1.2));

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.