Esempio n. 1
0
 static internal string IAmPrinting(object someobj)
 {
     if (someobj is IntelligentCreature)
     {
         if (someobj is Transformer)
         {
             IntelligentCreature tr = someobj as Transformer;
             return(Convert.ToString(tr));
         }
         if (someobj is Human)
         {
             IntelligentCreature h = someobj as Human;
             return(Convert.ToString(h));
         }
         IntelligentCreature ic = someobj as IntelligentCreature;
         return(Convert.ToString(ic));
     }
     return("Все плохо");
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            IntelligentCreature Roman      = new Human(1860, " Телесный ");
            IntelligentCreature Bumbulbee  = new Transformer(6000, " Желтый ", 10);
            IEngine             IBumbulbee = new Transformer(6000, " Желтый ", 10);

            Roman.Display();
            Bumbulbee.Display();
            Console.WriteLine(Bumbulbee.Start());
            Console.WriteLine(IBumbulbee.Start());
            Console.WriteLine();
            Console.WriteLine(Bumbulbee is Transformer);
            Console.WriteLine(Bumbulbee is IntelligentCreature);
            IEngine             v8  = Bumbulbee as IEngine;
            IntelligentCreature man = Bumbulbee as Transformer;

            Console.WriteLine(v8);
            Console.WriteLine(man);
            Console.WriteLine();
            Car ford = new Car();

            Console.WriteLine(ford.ToString());
            Console.WriteLine();

            IntelligentCreature Optimus  = new Transformer(12000, "red", 100);
            IntelligentCreature Megatron = new Transformer(12000, "black", 200);
            IntelligentCreature Vlados   = new Human(1850, "white");
            IntelligentCreature Valik    = new Human(1840, "white");

            dynamic[] PrinterArray = { Optimus, Megatron, Vlados, Valik };
            Console.WriteLine("Printer");
            Console.WriteLine(Printer.IAmPrinting(Optimus));
            Console.WriteLine(Printer.IAmPrinting(Vlados));
            Console.WriteLine(Printer.IAmPrinting(Valik));
            Console.WriteLine(Printer.IAmPrinting(Megatron));
            Console.ReadLine();
        }