static void Main(string[] args) { SimpleMath math = new SimpleMath(); math.SetMathHandler((message, result) => { Console.WriteLine($"Message: {message}, result: {result}"); }); math.Add(10, 10); }
static void Main(string[] args) { // Зарегистрировать делегат как лямбда-выражение. SimpleMath m = new SimpleMath(); m.SetMathHandler((string msg, int result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); m.Add(10, 5); Console.ReadLine(); }
static void Main(string[] args) { // Register w/ delegate as a lambda expression. SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Lambda Message: {0}, Result: {1}", msg, result); }); // This will execute the lambda expression. m.Add(10, 10); m.SetMathHandler(delegate(string msg, int result) { Console.WriteLine("Anonymous Delegate Message: {0}, Result: {1}", msg, result); }); m.Add(11, 11); m.SetMathHandler(ShowResult); m.Add(12, 12); Console.ReadLine(); }
static void Main(string[] args) { SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); m.Add(10, 10); }
static void Main( string[] args ) { // Register w/ delegate as a lambda expression. SimpleMath m = new SimpleMath(); m.SetMathHandler(( msg, result ) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); // This will execute the lambda expression. m.Add(10, 10); Console.ReadLine(); }
static void Main(string[] args) { //Register with delefate as a lambda expression SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine($"Message: {msg}, Result: {result}"); }); //This will execute the lambda expression m.Add(10, 10); }
static void Main(string[] args) { // Register w/ delegate as a lambda expression. SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); // This will execute the lambda expression. m.Add(10, 10); Console.ReadLine(); }
static void Main(string[] args) { // Регистрируем делегат через lambda-выражение SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); m.Add(10, 10); Console.ReadLine(); }
static void Main(string[] args) { SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); m.Add(10, 11); //VerySimpleDelegate d = new VerySimpleDelegate(() => "Enjoy your string"); VerySimpleDelegate d = () => "Enjoy your string"; Console.WriteLine(d()); Console.ReadLine(); }
static void Main(string[] args) { SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); m.Add(10, 10); Console.ReadLine(); VerySimpleDelegate d = new VerySimpleDelegate(() => { return(" Text"); }); Console.WriteLine(d()); }
static void Main(string[] args) { VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string"); }); //Register with delegate as a lambda expression SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine($"Message {msg}, Result: {result}"); }); //This will execute the lambda expression m.Add(10, 10); Console.WriteLine(d()); Console.Read(); }
static void Main(string[] args) { SimpleMath m = new SimpleMath(); //使用Lambda表达式与有多个参数的委托交互 m.SetMathHandler((msg, result) =>// (string msg,int result)=> { Console.WriteLine("Message: {0},Result: {1}", msg, result); }); m.Add(10, 10); //与无参数的委托交互可以这样 VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string!"); }); Console.WriteLine(d.Invoke()); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Lambdas with Multiple or no Params! *****\n"); // Register w/ delegate as a lambda expression. SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); // This will execute the lambda expression. m.Add(10, 10); VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string!"); }); Console.WriteLine(d.Invoke()); Console.ReadLine(); }