예제 #1
0
        static void Main(string[] args)
        {
            int a = 50, b = 15;
            var am = new AdvancedMath();

            BinaryOperator[] operators =
            {
                SimpleMath.Plus,
                SimpleMath.Minus,
                am.Multiply,
                am.Divide
            };

            for (int i = 0; i < operators.Length; i++)
            {
                var result = operators[i](a, b);
                var name   = operators[i].Method.Name;

                Console.WriteLine("{0} {1} {2} = {3}", a, name, b, result);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            int a = 50, b = 15;

            BinaryOperator opr    = SimpleMath.Plus; //public static function
            int            result = opr(a, b);

            Console.WriteLine(result);

            opr    = SimpleMath.Minus; //note same opr is reassigned
            result = opr(a, b);
            Console.WriteLine(result);

            var am                = new AdvancedMath();

            opr    = am.Multiply; //public non static method
            result = opr(a, b);
            Console.WriteLine(result);

            opr    = am.getModDelegate(); //you got access to private method
            result = opr(a, b);
            Console.WriteLine(result);
        }