コード例 #1
0
        public static void Main()
        {
            // Build a collection of all vehicles that fly
            List <Aircraft> flyingThings = new List <Aircraft>();
            Aircraft        plane1       = new Aircraft("ZVxTN10", 2)
            {
                Color = VehicleColors.black
            };
            Aircraft helicopter2 = new Aircraft("VYX5RN", 1)
            {
                Color = VehicleColors.blue
            };
            Aircraft bigPlane3 = new Aircraft("RAS8490", 3)
            {
                Color = VehicleColors.green
            };

            flyingThings.Add(plane1);
            flyingThings.Add(helicopter2);
            flyingThings.Add(bigPlane3);
            // With a single `foreach`, have each vehicle Fly()
            foreach (var flyingThing in flyingThings)
            {
                flyingThing.Fly();
            }

            // Build a collection of all vehicles that operate on roads
            List <Car> roadThings   = new List <Car>();
            Car        roadWarrior1 = new Car("Toyota", "Prius", 2014);
            Car        roadWarrior2 = new Car("Toyota", "Camry", 2015);
            Car        roadWarrior3 = new Car("Toyota", "Supra", 2019);

            roadThings.Add(roadWarrior1);
            roadThings.Add(roadWarrior2);
            roadThings.Add(roadWarrior3);
            // With a single `foreach`, have each road vehicle Drive()
            foreach (var roadThing in roadThings)
            {
                roadThing.Drive();
            }

            // Build a collection of all vehicles that operate on water
            List <Watercraft> waterThings = new List <Watercraft>();
            Watercraft        fancyBoat1  = new Watercraft(222, "20 ft");
            Watercraft        fancyBoat2  = new Watercraft(350, "30 ft");
            Watercraft        fancyBoat3  = new Watercraft(800, "60 ft");

            waterThings.Add(fancyBoat1);
            waterThings.Add(fancyBoat2);
            waterThings.Add(fancyBoat3);
            // With a single `foreach`, have each water vehicle Drive()
            foreach (var waterThing in waterThings)
            {
                waterThing.Drive();
            }

            helicopter2.Refuel();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: bobbybaxter/MyGarage
        static void Main(string[] args)
        {
            var myCar = new HondaAccord();

            myCar.ListFeatures();
            myCar.Refuel();
            myCar.Drive();
            myCar.Brake();

            var myAircraft = new Aircraft();

            myAircraft.Refuel();
            myAircraft.Fly();
            myAircraft.Brake();

            var myWatercraft = new Watercraft();

            myWatercraft.Refuel();
            myWatercraft.Drive();
            myWatercraft.Brake();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to my garage!");
            Console.WriteLine(new string('-', 75));



            // aircraft
            var helicopter = new Aircraft("green", "Black Hawk", "360 gallons", 13);
            var glider     = new Aircraft("yellow", "Skylark 2", "0 gallons", 1);
            var blimp      = new Aircraft("white", "Skyship", "682 gallons", 12);


            List <Aircraft> AllMyAircraft = new List <Aircraft>();

            AllMyAircraft.Add(helicopter);
            AllMyAircraft.Add(glider);
            AllMyAircraft.Add(blimp);


            foreach (Aircraft Aircraft in AllMyAircraft)
            {
                Aircraft.Fly();
            }

            Console.WriteLine(new string('-', 75));



            // cars
            var hondaCivic = new Car("grey", "Civic", "12 gallon", 4);
            var mazda3     = new Car("dark blue", "Mazda hatchback", "14 gallon", 5);
            var bmw        = new Car("white", "BMW  1 Series", "12 gallons", 4);


            List <Car> AllMyCars = new List <Car>();

            AllMyCars.Add(hondaCivic);
            AllMyCars.Add(mazda3);
            AllMyCars.Add(bmw);


            foreach (Car Car in AllMyCars)
            {
                Car.Drive();
            }

            Console.WriteLine(new string('-', 75));



            // watercraft
            var canoe     = new Watercraft("brown", "outrigger", "0 gallons", 2);
            var jetski    = new Watercraft("blue", "WaveRunner", "16 gallons", 2);
            var submarine = new Watercraft("black", "U-Boat", "fuel cells", 25);


            List <Watercraft> AllMyWatercraft = new List <Watercraft>();

            AllMyWatercraft.Add(canoe);
            AllMyWatercraft.Add(jetski);
            AllMyWatercraft.Add(submarine);


            foreach (Watercraft Watercraft in AllMyWatercraft)
            {
                Watercraft.Drive();
            }



            Console.ReadKey();
        }