static void PerformLambdas() { var mathService = new Lambdas.MathService(); // Below to is identical, syntax sugar. mathService.MathPerformed += delegate(object sender, Lambdas.MathPerformedEventArgs e) { Console.WriteLine("Event no lambda: " + e.Result); }; mathService.MathPerformed += (sender, e) => Console.WriteLine("Event with lambda: " + e.Result); mathService.MathPerformedCustom += res => Console.WriteLine("Custom event with lambda: " + res); mathService.MathPerform += res => Console.WriteLine("Custom event with lambda Action<T>, Func<T>: " + res); mathService.MultiplyNumbers(1, 1); mathService.MultiplyNumbersCustom(1, 2); mathService.CalculateNumbers(1, 3, (a, b) => a * b); mathService.CalculateNumbers(1, 25, (a, b) => a * b); mathService.CalculateActionNumbers(1, 4, (a, b) => a * b); mathService.CalculateActionNumbers(1, 26, (a, b) => a * b); }
static void Main(string[] args) { MathService mathService = new MathService(); mathService.MathPerformed += OnMathPerformed; mathService.MultiplyNumbers(15.6, 77.8); }