"Original" Generic delegate

Source: Internet
Author: User

//no parameter, no return value, with action non-generic delegate;Action action = () = Console.WriteLine ("no parameter, action with no return value");            Action (); //With parameters, no return value, with action generic delegate;//The action<> generic delegate has 15 overloads, from 1 parameters to 15 parameters;//1 parameters, no return valueaction<int> action1 = n =Console.WriteLine (n.tostring ()); Action1 (123);//returns the result "123"//2 parameters, no return valueaction<string,int> Action2 = (s, i) = Console.WriteLine ("first parameter Value--{0}, second parameter value--{1}", S,i); Action2 ("haha",456);//returns the result "first parameter value--haha, second parameter value--456"//3 parameters, no return value .... 15 parameters no return value ....             //there are or no parameters, but there are 1 return values with the func<> generic delegate, but one thing to note is that the return value type must be written in the last;func< parameter 1, parameter 2, Parameter 3 .... , return value type >//no parameters, with return valuesfunc<string> func = () = {return "no parameters, but there is a return value"; }; Console.WriteLine (func ());//returns the result "no parameter, but has a return value"//has a parameter that has a return valuefunc<int,string> func2=n=>{return(n2).            ToString ();}; Console.WriteLine (Func2 (5));//returns the result "ten"Console.read ();

"Original" Generic delegate

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.