Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Extending an Interface *****\n");
            MyCalc c = new MyCalc();
            Console.WriteLine("1 + 2 = {0}", c.Add(1, 2));
            Console.WriteLine("1 - 2 = {0}", c.Subtract(1, 2));
            Console.WriteLine("30 - 9 = {0}", ((IBasicMath) c).Subtract(30, 9));

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Extending an interface *****\n");

            // Call IBasicMath members from MyCalc object.
            MyCalc c = new MyCalc();

            Console.WriteLine("1 + 2 = {0}", c.Add(1, 2));
            Console.WriteLine("1 - 2 = {0}", c.Subtract(1, 2));

            // Can also cast into IBasicMath to invoke extension.
            Console.WriteLine("30 - 9 = {0}",
                              ((IBasicMath)c).Subtract(30, 9));

            // This would NOT work!
            // IBasicMath itfBM = new IBasicMath();
            // itfBM.Subtract(10, 10);
            Console.ReadLine();
        }