using System;
namespace Articulos.Cap04
{
public sealed class ExpresionLambdaComoParametro
{
// Método que se encarga de operar los operandos
// de una operación binaria (e.g., suma, resta, producto, cociente):
public static int Calcular(Func<int, int, int> operacion, int num1, int num2)
{
return operacion (num1, num2);
}
public static void Main()
{
Console.Write ("Escriba un número entero: ");
int num1 = Int32.Parse(Console.ReadLine());
Console.Write ("Escribe otro número entero: ");
int num2 = Int32.Parse(Console.ReadLine());
Console.WriteLine ("{0} + {1} = {2}", num1, num2, Calcular ( (x,y) => x + y, num1, num2));
Console.WriteLine ("{0} - {1} = {2}", num1, num2, Calcular ( (x,y) => x - y, num1, num2));
Console.WriteLine ("{0} * {1} = {2}", num1, num2, Calcular ( (x,y) => x * y, num1, num2));
Console.WriteLine ("{0} / {1} = {2}", num1, num2, Calcular ( (x,y) => x / y, num1, num2));
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIEFydGljdWxvcy5DYXAwNAp7CiAgICBwdWJsaWMgc2VhbGVkIGNsYXNzIEV4cHJlc2lvbkxhbWJkYUNvbW9QYXJhbWV0cm8KICAgIHsKICAgICAgICAvLyBNw6l0b2RvIHF1ZSBzZSBlbmNhcmdhIGRlIG9wZXJhciBsb3Mgb3BlcmFuZG9zIAogICAgICAgIC8vIGRlIHVuYSBvcGVyYWNpw7NuIGJpbmFyaWEgKGUuZy4sIHN1bWEsIHJlc3RhLCBwcm9kdWN0bywgY29jaWVudGUpOgogICAgICAgIHB1YmxpYyBzdGF0aWMgaW50IENhbGN1bGFyKEZ1bmM8aW50LCBpbnQsIGludD4gb3BlcmFjaW9uLCBpbnQgbnVtMSwgaW50IG51bTIpCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gb3BlcmFjaW9uIChudW0xLCBudW0yKTsKICAgICAgICB9CiAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlICgiRXNjcmliYSB1biBuw7ptZXJvIGVudGVybzogIik7CiAgICAgICAgICAgIGludCBudW0xID0gSW50MzIuUGFyc2UoQ29uc29sZS5SZWFkTGluZSgpKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZSAoIkVzY3JpYmUgb3RybyBuw7ptZXJvIGVudGVybzogIik7CiAgICAgICAgICAgIGludCBudW0yID0gSW50MzIuUGFyc2UoQ29uc29sZS5SZWFkTGluZSgpKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiezB9ICsgezF9ID0gezJ9IiwgbnVtMSwgbnVtMiwgQ2FsY3VsYXIgKCAoeCx5KSA9PiB4ICsgeSwgbnVtMSwgbnVtMikpOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoInswfSAtIHsxfSA9IHsyfSIsIG51bTEsIG51bTIsIENhbGN1bGFyICggKHgseSkgPT4geCAtIHksIG51bTEsIG51bTIpKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJ7MH0gKiB7MX0gPSB7Mn0iLCBudW0xLCBudW0yLCBDYWxjdWxhciAoICh4LHkpID0+IHggKiB5LCBudW0xLCBudW0yKSk7CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiezB9IC8gezF9ID0gezJ9IiwgbnVtMSwgbnVtMiwgQ2FsY3VsYXIgKCAoeCx5KSA9PiB4IC8geSwgbnVtMSwgbnVtMikpOwogICAgICAgIH0KICAgIH0KfQ==