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); VerySimpleDelegate d = () => { return "Enjoy your string!"; }; Console.WriteLine(d.Invoke()); Console.ReadLine(); }
private static void Main(string[] args) { var m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); }); m.Add(10, 10); var d = new VerySimpleDelegate(() => { return("Enjoy your string!"); }); Console.WriteLine(d()); Console.ReadLine(); }
static void Main(string[] args) { // Register with delegate as a lambda expression SimpleMath m = new SimpleMath(); m.SetMathHandler((msg, result) => { Console.WriteLine($"Message: { msg }\tResult: { result }"); }); // this will execute the Lambda expression m.Add(10, 10); Console.Write("\n\nPress <Enter> to Exit. . ."); Console.ReadLine(); }
static void Main(string[] args) { // Register with 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); // Prints "Enjoy your string!" to the console. VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string!"); }); Console.WriteLine("Result from zero param delegate: {0}", d()); }