C # syntax (framework comes with delegates and async)

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;namespaceAsync Thread {classAsynchronous {Private inti =0;  Public voidShow () { for(inti =0; I <5; i++)      {        //The system comes with a delegate (parameter has no return value, parameter has a return value)Action action =NewAction (Index);//callback function (the second parameter of an asynchronous execution delegate)AsyncCallbackAsync=NewAsyncCallback ((x) = Console.WriteLine ("I am the callback value {0}", x.asyncstate)); //asynchronous execution of a delegate (callback function, parameters of a callback function)Action. BeginInvoke (Async, A); }    }     Public voidIndex () {Console.WriteLine ("The current thread ID is {0}", Thread.CurrentThread.ManagedThreadId); Thread.Sleep ( +); Console.WriteLine ("I am the {0} name", i); I++; }  }}

<!--comes with a delegate--

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceλ-expression { Public classLambdaa { Public voidShow () {//System self-delegation with parameter no return value (up to 16 parameters supported)action<int,string,BOOL> action = (x, y, z) = = Console.WriteLine (x + y +z); Action (1,"2",true); //System Self-delegation with parameters with return value (up to 16 parameters and one return value)func<int,int,int> func = (x, y) + x +y; Console.WriteLine (Func (2,3)); }  }}

C # syntax (framework comes with delegates and async)

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.