コード例 #1
0
        static void Main(string[] args)
        {
            // Build a collection of all vehicles that fly

            // With a single `foreach`, have each vehicle Fly()



            // Build a collection of all vehicles that operate on roads

            // With a single `foreach`, have each road vehicle Drive()



            // Build a collection of all vehicles that operate on water

            // With a single `foreach`, have each water vehicle Drive()

            Cessna     blueCessna    = new Cessna();
            Motorcycle redMotorcycle = new Motorcycle();
            JetSki     pinkJetski    = new JetSki();

            List <IAirVehicle> airVehicles = new List <IAirVehicle>()
            {
                blueCessna
            };
            List <ILandVehicle> landVehicles = new List <ILandVehicle>()
            {
                redMotorcycle
            };
            List <IWaterVehicle> waterVehicles = new List <IWaterVehicle>()
            {
                pinkJetski
            };

            foreach (IWaterVehicle waterVehicle in waterVehicles)
            {
                waterVehicle.Drive();
            }
            foreach (IAirVehicle airVehicle in airVehicles)
            {
                airVehicle.Fly();
            }
            foreach (ILandVehicle landVehicle in landVehicles)
            {
                landVehicle.Drive();
            }
        }
コード例 #2
0
        public static void Main()
        {
            Cessna fxs  = new Cessna();
            Piper  b540 = new Piper();

            // Build a collection of all vehicles that fly
            List <IFly> planes = new List <IFly>()
            {
                fxs, b540
            };

            // With a single `foreach`, have each vehicle Fly()
            foreach (IFly plane in planes)
            {
                plane.Fly();
            }

            Motorcycle honda = new Motorcycle();
            Slingshot  slr   = new Slingshot();
            // Build a collection of all vehicles that operate on roads
            List <IDrive> bikes = new List <IDrive>()
            {
                honda, slr
            };

            // With a single `foreach`, have each road vehicle Drive()
            foreach (IDrive bike in bikes)
            {
                bike.Drive();
            }

            JetSki    kawasaki = new JetSki();
            Catamaran catana   = new Catamaran();
            // Build a collection of all vehicles that operate on water
            List <IAmphibious> boats = new List <IAmphibious>()
            {
                kawasaki, catana
            };

            // With a single `foreach`, have each water vehicle Drive()
            foreach (IAmphibious boat in boats)
            {
                boat.Drive();
            }
        }
コード例 #3
0
        public static void Main()
        {
            Cessna     plane    = new Cessna();
            Blimp      blimpy   = new Blimp();
            Motorcycle bike     = new Motorcycle();
            Truck      bigtruck = new Truck();
            JetSki     zippy    = new JetSki();
            SpeedBoat  speedy   = new SpeedBoat();

            // Build a collection of all vehicles that fly

            List <IAir> FlyingVehicles = new List <IAir>()
            {
                plane, blimpy
            };

            // With a single `foreach`, have each vehicle Fly()

            FlyingVehicles.ForEach(v => v.Fly());


            // Build a collection of all vehicles that operate on roads

            List <ILand> LandVehicles = new List <ILand>()
            {
                bike, bigtruck
            };

            // With a single `foreach`, have each road vehicle Drive()

            LandVehicles.ForEach(v => v.Drive());


            // Build a collection of all vehicles that operate on water

            List <IWater> WaterVehicles = new List <IWater>()
            {
                zippy, speedy
            };

            // With a single `foreach`, have each water vehicle Drive()

            WaterVehicles.ForEach(v => v.Drive());
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: aleshakay/Garage
        static void Main(string[] args)
        {
            // Build a collection of all vehicles that fly
            // With a single `foreach`, have each vehicle Fly()
            var boeing    = new Airplane(200, VehColor.silver, 300);
            var heli      = new Helicopters(100, VehColor.black, 8);
            var aircrafts = new List <Aircraft> {
                boeing, heli
            };

            foreach (var aircraft in aircrafts)
            {
                aircraft.Flying(4);
            }

            // Build a collection of all vehicles that operate on roads
            // With a single `foreach`, have each road vehicle Drive()
            var accord = new HondaCar(10, VehColor.pink, 4);
            var pilot  = new HondaCar(20, VehColor.silver, 6);
            var cars   = new List <Car> {
                accord, pilot
            };

            foreach (var car in cars)
            {
                car.Driving();
            }

            // Build a collection of all vehicles that operate on water
            // With a single `foreach`, have each water vehicle Drive()
            var yamaha      = new JetSki(25, VehColor.silver, 1);
            var topmaz      = new JetSki(15, VehColor.blue, 2);
            var watercrafts = new List <Watercraft> {
                yamaha, topmaz
            };

            foreach (var watercraft in watercrafts)
            {
                watercraft.Driving(4);
            }
        }
コード例 #5
0
        public static void Main()
        {
            Cessna     plane           = new Cessna();
            Car        Accord          = new Car();
            FighterJet Jet             = new FighterJet();
            JetSki     Floaty          = new JetSki();
            Motorcycle AndreBikey      = new Motorcycle();
            Boat       BoatyMcBoatFace = new Boat();

            // Build a collection of all vehicles that fly
            List <IAir> FlyingThings = new List <IAir>()
            {
                plane, Jet
            };

            // With a single `foreach`, have each vehicle Fly()
            FlyingThings.ForEach(ft => ft.Fly());



            // Build a collection of all vehicles that operate on roads
            List <ILand> RoadVehicles = new List <ILand>()
            {
                AndreBikey, Accord
            };

            // With a single `foreach`, have each road vehicle Drive()
            RoadVehicles.ForEach(rv => rv.Drive());



            // Build a collection of all vehicles that operate on water
            List <IWater> WaterVehicles = new List <IWater>()
            {
                BoatyMcBoatFace, Floaty
            };

            // With a single `foreach`, have each water vehicle Drive()
            WaterVehicles.ForEach(wv => wv.Drive());
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Boeing boeing = new Boeing();
            Cessna cessna = new Cessna();

            // Build a collection of all vehicles that fly
            List <IFlyingVehicle> flyingVehicles = new List <IFlyingVehicle>()
            {
                boeing,
                cessna
            };

            // With a single `foreach`, have each vehicle Fly()
            flyingVehicles.ForEach(vehicle => vehicle.Fly());


            HouseBoat houseboat = new HouseBoat();
            JetSki    jetski    = new JetSki();
            // Build a collection of all vehicles that operate on water
            List <ISwimmingVehicle> swimmingVehicles = new List <ISwimmingVehicle>()
            {
                houseboat,
                jetski
            };

            // With a single `foreach`, have each water vehicle Drive()
            swimmingVehicles.ForEach(vehicle => vehicle.Drive());

            Motorcycle motorcycle = new Motorcycle();
            RAV4       rav4       = new RAV4();
            // Build a collection of all vehicles that operate on roads
            List <IDrivingVehicle> drivingVehicles = new List <IDrivingVehicle>()
            {
                motorcycle,
                rav4
            };

            // With a single `foreach`, have each road vehicle Drive()
            drivingVehicles.ForEach(vehicle => vehicle.Drive());
        }
コード例 #7
0
        public static void Main()
        {
            Cessna     M1     = new Cessna();
            Cessna     M2     = new Cessna();
            Motorcycle Harley = new Motorcycle();
            JetSki     JetSki = new JetSki();

            // Build a collection of all vehicles that fly
            List <IFlyingVehicle> Flying = new List <IFlyingVehicle>();

            Flying.Add(M1);
            Flying.Add(M2);
            // With a single `foreach`, have each vehicle Fly()
            foreach (IFlyingVehicle plane in Flying)
            {
                plane.Fly();
            }
            // Build a collection of all vehicles that operate on roads
            List <ILandVehichle> Driving = new List <ILandVehichle>();

            Driving.Add(Harley);
            // With a single `foreach`, have each road vehicle Drive()
            foreach (ILandVehichle car in Driving)
            {
                car.Drive();
            }


            // Build a collection of all vehicles that operate on water
            List <IWaterVehicle> Boating = new List <IWaterVehicle>();

            Boating.Add(JetSki);
            // With a single `foreach`, have each water vehicle Drive()
            foreach (IWaterVehicle boat in Boating)
            {
                boat.Drive();
            }
        }