Example #1
0
        static void Main(string[] args)
        {
            double a = 10;
            double b = 12;

            BinaryNumericOperation op = CalculationService.ShowSum;

            op += CalculationService.ShowMax;

            op.Invoke(a, b);
        }
Example #2
0
        static void Main(string[] args)
        {
            double a = 10;
            double b = 5;

            BinaryNumericOperation op = CalculationService.Sum;

            double result = op.Invoke(a, b);

            Console.WriteLine(result);
        }
        static void Main(string[] args)
        {
            double a = 10;
            double b = 12;

            BinaryNumericOperation op = CalculationService.ShowSum;

            op += CalculationService.ShowMax;

            op.Invoke(a, b);
            //op(a, b); -- esta sintaxe também poderia ser usada
        }
Example #4
0
        static void Main(string[] args)
        {
            double a = 10;
            double b = 12;

            //Referenciando dois métodos
            BinaryNumericOperation op = CalculationService.ShowSum;

            op += CalculationService.ShowMax;

            //Como ele não tem retorno, então não posso recebê-lo na variável
            op.Invoke(a, b);
            //Pode ser também op(a, b)
        }
Example #5
0
        static void Main(string[] args)
        {
            double a = 10.0;
            double b = 12.0;

            //BinaryNumericOperation op = CalculationService.Max;
            /////////////////////////////////////////////////Sum

            BinaryNumericOperation op = new BinaryNumericOperation(CalculationService.Sum);

            double result = op.Invoke(a, b);

            Console.WriteLine(result);
        }
Example #6
0
        static void Main(string[] args)
        {
            double a = 10;
            double b = 12;

            // BinaryNumericOperation op = CalculationService.Sum;
            BinaryNumericOperation op = new BinaryNumericOperation(CalculationService.Sum);
            double result1            = op(a, b);
            double result2            = op.Invoke(a, b);

            Console.WriteLine(result1);
            Console.WriteLine(result2);

            //O método Square não casa com a assintatura delegate definida acima
            //BinaryNumericOperation op = new BinaryNumericOperation(CalculationService.Square);
        }
Example #7
0
        static void Main(string[] args)
        {
            double a = 10;
            double b = 12;

            BinaryNumericOperation op  = CalculationService.Sum;
            BinaryNumericOperation op2 = CalculationService.Max;

            double result = op(a, b);
            double max    = op2.Invoke(a, b);
            double square = CalculationService.Square(a);

            Console.WriteLine("Result = " + result);
            Console.WriteLine("Max = " + max);
            Console.WriteLine("Square = " + square);
        }
Example #8
0
        static void Main(string[] args)
        {
            double a = 10;
            double b = 12;

            BinaryNumericOperation       opSum    = CalculationService.Sum;
            BinaryNumericOperation       opMax    = CalculationService.Max;
            BinaryNumericOperationSquare opSquare = CalculationService.Square;

            double sum    = opSum.Invoke(a, b);
            double max    = opMax.Invoke(a, b);
            double square = opSquare.Invoke(a);

            Console.WriteLine($"SUM : {sum}");
            Console.WriteLine($"Max : {max}");
            Console.WriteLine($"Square : {square}");
        }
Example #9
0
        public static void Main(string[] args)
        {
            /*
             * Multicast delegates:
             * .Delegates que guardam referencia para mais de um metodo
             * .Para se adcionar referencia, pode se usar o operador +=
             * .A chamada Invoke(ou sintaxe reduzida) executa todos os metodos na ordem em que foram adcionados
             * .Seu uso faz setido para metodos void
             */

            double a = 10.0f;
            double b = 12.0f;

            BinaryNumericOperation op = CalculationService.ShowSum;

            op += CalculationService.ShowMax;

            op.Invoke(a, b);
        }
        private static void Main()
        {
            const double a = 10;
            const double b = 12;

            BinaryNumericOperation op = CalculationService.Max;

//            var sum = CalculationService.Max(a, b);
//            var square = CalculationService.Square(a);

            var d = op.Invoke(a, b);

//            Console.WriteLine(sum);
//            Console.WriteLine(square);

            ShowMath showMath = CalculationService.ShowMax;

            showMath += CalculationService.ShowSum;

            showMath(a, b);
        }