C # delegate base 4--generic delegate Func

Source: Internet
Author: User

C # commissioned the basic series was originally published in February 2011 in my Sina blog, now it will be like this blog.

In order to facilitate development,. The net Base Class library provides several predefined delegates for the most commonly used scenarios in actual development, and these predefined delegates are used widely, such as when writing lambda expressions and developing parallel computing programs.

predefined generic delegate func

Class program
{
        double addint (int x, int y)
        {return
            x + y;
        }

        String AddString (string s1, string s2)
        {return
            s1 + s2;
        }

        static void Main (string[] args)
        {program
            p = new program ();

            When the first two arguments are int, they run a double, and the last parameter is consistent with the AddInt return value
            func<int, int, double> funcint = p.addint;
            Console.WriteLine ("Funcint value is {0}", funcint);

            Func<string, String, string> funcstring = p.addstring;
            Console.WriteLine ("Funcstring value is {0}", Funcstring ("AAA", "BBB"));
        }



This article refers to the content of the agent from Jin Xu-liang's ". NET 4.0 object-oriented Programming"
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.