Beispiel #1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Aviation aviation = new Aviation();
            Cargo    cargo    = new Cargo();
            Military military = new Military();
            Pasanger pasanger = new Pasanger();
            Ty134    ty134    = new Ty134();
            Boing    boing    = new Boing();

            cargo.addInfo();
            Console.WriteLine('\n');
            military.addInfo();
            Console.WriteLine('\n');
            pasanger.addInfo();
            Console.WriteLine('\n');

            Console.ForegroundColor = ConsoleColor.Magenta;
            aviation.Type();
            cargo.Type();
            military.Type();
            pasanger.Type();
            ty134.Type();
            boing.Type();
            Console.WriteLine('\n');

            Console.ForegroundColor = ConsoleColor.White;
            bool fly = pasanger is Aviation;

            if (fly)
            {
                Aviation confOne = (Aviation)pasanger;
                confOne.Type();
            }

            Console.ForegroundColor = ConsoleColor.Red;
            ITransport confTwo   = military as ITransport;
            ITrans     confThree = cargo as ITrans;

            if (confTwo != null)
            {
                confTwo.Info();
            }

            if (confThree != null)
            {
                confThree.Info("fsfe");
            }



            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(cargo.ToString());

            Console.ForegroundColor = ConsoleColor.Green;
            Transport obj = pasanger as Transport;//можно ли преобразовать

            Console.WriteLine(obj.GetType());

            Console.ForegroundColor = ConsoleColor.Yellow;
            if (military is Transport)//преднадлежит
            {
                Console.WriteLine(true + "\n");
            }

            Console.ForegroundColor = ConsoleColor.Magenta;
            Transport[] mas = { cargo, military, pasanger };
            foreach (Transport x in mas)
            {
                Console.WriteLine(Printer.iAmPrinting(x));
            }

            Console.ReadKey();
        }
Beispiel #2
0
 public static string iAmPrinting(Transport someobj)
 {
     return(someobj.ToString());
 }