static void Main(string[] args)
        {
            Console.WriteLine("*** Fun with intarface name calshes ***\n");
            Octagon oct = new Octagon();

            IDrowToForm idtf = (IDrowToForm)oct;

            idtf.Draw();

            IDrawToMemory idtm = (IDrawToMemory)oct;

            idtm.Draw();

            IDrawToPrinter idtp = (IDrawToPrinter)oct;

            idtp.Draw();

            ((IDrowToForm)oct).Draw();

            if (oct is IDrawToPrinter dp)
            {
                dp.Draw();
            }

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Octagon     octagon = new Octagon();
            IDrawToForm form    = octagon;

            form.Draw();

            IDrawToMemory memory = octagon;

            memory.Draw();

            IDrawToPrinter printer = octagon;

            printer.Draw();

            // Сокращенная нотация, если переменная интерфейса не нужна
            ((IDrawToPrinter)octagon).Draw();

            // Можно было бы также использовать ключевое слово as
            if (octagon is IDrawToMemory)
            {
                ((IDrawToMemory)octagon).Draw();
            }
            Console.ReadLine();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Interface Name Clashes *****\n");

            //  All of these invocations call the
            //  same Draw() method.
            Octagon oct = new Octagon();

            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.Draw();
            //  Shorthand notation if you don't need
            //  the interface variable for later use.
            ((IDrawToForm)oct).Draw();

            //  Could also use the "is" keyword.
            if (oct is IDrawToForm dtm)
            {
                dtm.Draw();
            }

            IDrawToPrinter itfPrinter = (IDrawToPrinter)oct;

            itfPrinter.Draw();

            IDrawToMemory itfMemory = (IDrawToMemory)oct;

            itfMemory.Draw();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("****** Fun with Interface Name Clashes ******\n");
            // All of these invocations call
            // the same Draw() method.
            Octagon     oct     = new Octagon();
            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.Draw();
            IDrawToPrinter itfPrinter = (IDrawToPrinter)oct;

            itfPrinter.Draw();
            IDrawToMemory itfMemory = (IDrawToMemory)oct;

            itfMemory.Draw();
            // We now must use casting to acces the Draw() members.
            Console.WriteLine();
            ((IDrawToPrinter)oct).Draw();
            // Could also use the is keyword
            if (oct is IDrawToMemory)
            {
                ((IDrawToMemory)oct).Draw();
            }
            Console.ReadLine();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Octagon     oct  = new Octagon();
            IDrawToForm octF = (IDrawToForm)oct;

            octF.Draw();

            IDrawToMemory octM = (IDrawToMemory)octF;

            octM.Draw();

            IDrawToPrinter octP = (IDrawToPrinter)octF;

            octM.Draw();

            Console.ReadLine();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Interface Name Clashes *****\n");
            // All of these invocations call the
            // same Draw() method!
            Octagon oct = new Octagon();
            //oct.Draw() is no longer available w/o cast
            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.Draw();
            IDrawToPrinter itfPriner = (IDrawToPrinter)oct;

            itfPriner.Draw();
            IDrawToMemory itfMemory = (IDrawToMemory)oct;

            itfMemory.Draw();
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Interface Name Clashes *****\n");

            // All of these invocations call the
            // same Draw() method!
            Octagon oct = new Octagon();

            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.Draw();

            IDrawToMemory itfMemory = (IDrawToMemory)oct;

            itfMemory.Draw();

            IDrawToPrinter itfPrinter = (IDrawToPrinter)oct;

            itfPrinter.Draw();

            // Must use casting to access the Draw() when explicitly implemented.
            IDrawToForm itfForm2 = (IDrawToForm)oct;

            itfForm2.Draw();

            // Shorthand notation if you don't need
            // the interface variable for later use.
            ((IDrawToMemory)oct).Draw();

            // Could also use the "is" keyword.
            if (oct is IDrawToPrinter)
            {
                ((IDrawToPrinter)oct).Draw();
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Interface Name Clashes *****\n");
            Octagon     oct     = new Octagon();
            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.Draw();

            /*
             * ((IDrawToPrinter)oct).Draw();
             *
             * if (oct is IDrawToMemory)
             *  ((IDrawToMemory)oct).Draw();
             */
            IDrawToPrinter itfPriner = (IDrawToPrinter)oct;

            itfPriner.Draw();

            IDrawToMemory itfMemory = (IDrawToMemory)oct;

            itfMemory.Draw();

            Console.ReadLine();
        }