Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace delegatedemo1{class Program {static void One () {Console.WriteLine ("one"); throw new Exception ("Error in one"); } static void () {Console.WriteLine ("n"); } static void Main (string[] args) {string mid = ", middle part,"; /*func<string, String>: Accepts a string argument, returns a string in this anonymous method cannot use Break,goto,continue to jump outside of the function, nor to jump inside func<string, string> Anondel = delegate (string param) {param + = mid; param + = "and this is End"; return param; }; Console.WriteLine (Anondel ("Start")); /*lambda =>: The required parameters are listed on the left (param) lambda +: The right defines the code that assigns the method implementation of the lambda variable */func<str ing, string> lambda = param => {param + = mid; param + = "and this is End"; return param; }; Console.WriteLine (Anondel ("lambda")); Lambda a parameter compiler adds an implicit return statement func<string, string> Oneparam = s = = string. Format ("Change uppercase {0}", S.toupper ()); Add the return statement shown func<string, string> oneparamr = s = = {return string. Format ("Change uppercase {0}", S.toupper ()); }; Console.WriteLine ("Oneparam is" + Oneparam ("Test")); Lambda two parameter compiler adds an implicit return statement func<double, double, double> towparams = (x, y) + x * y; Add the return statement shown func<double, double, double> TOWPARAMSR = (x, y) + = {Retur n x * y; }; Console.WriteLine ("Towparams is" + towparams (3,2)); Console.readkey (); } }}
C # Lambda learns a