Example #1
0
        static void Main(string[] args)
        {
            Octogon octo = new Octogon();

            octo.Draw();
            ((IDrawToForm)octo).Draw();
            ((IDrawToMemory)octo).Draw();
//            ((IDrawToPrinter)octo).Draw();

            IDrawToPrinter itfPrinter = octo as IDrawToPrinter;

            if (octo != null)
            {
                ((IDrawToPrinter)octo).Draw();
            }

            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            Octogon oct = new Octogon();

            //We not must use cast to access the draw()
            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.draw();

            //shorthand notation if you dont need the inerface
            //variable for later use
            ((IDrawToPrinter)oct).draw();

            //Could as use the is keyword
            if (oct is IDrawToMemory)
            {
                ((IDrawToMemory)oct).draw();
            }
            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Interface Name Clashes *****");
            // All of these invocations call the same Draw() method!

            Octogon     oct     = new Octogon();
            IDrawToForm itfForm = (IDrawToForm)oct;

            itfForm.Draw();

            // shorthand notation if variable not needed afterward
            ((IDrawToPrinter)oct).Draw();

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


            Console.ReadLine();
        }