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)