Beispiel #1
0
        public static void Main()
        {
            //------------------------------------------------------------------------
            // Build a collection of all vehicles that fly
            // With a single `foreach`, have each vehicle Fly()
            PassengerPlane plane1 = new PassengerPlane();
            PrivateJet     plane2 = new PrivateJet();
            Spaceship      plane3 = new Spaceship();
            //creat a list of planes
            var planes = new List <Aircraft>();

            planes.Add(plane1);
            planes.Add(plane2);
            planes.Add(plane3);
            //loop over the list with a foreach and call method Fly() for each one
            foreach (var plane in planes)
            {
                plane.Fly();
            }
            //--------------------------------------------------------------------------


            //------------------------------------------------------------------------
            // Build a collection of all vehicles that operate on roads
            // With a single `foreach`, have each road vehicle Drive()
            NissanLeaf  car1 = new NissanLeaf();
            NissanKicks car2 = new NissanKicks();
            NissanRogue car3 = new NissanRogue();
            //creat a list of cars
            var cars = new List <Car>();

            cars.Add(car1);
            cars.Add(car2);
            cars.Add(car3);
            //loop over the list with a foreach and call method Drive() for each one
            foreach (var car in cars)
            {
                car.Drive();
            }
            //--------------------------------------------------------------------------

            //--------------------------------------------------------------------------
            // Build a collection of all vehicles that operate on water
            // With a single `foreach`, have each water vehicle Drive()
            MotorBoat boat1 = new MotorBoat();
            RowBoat   boat2 = new RowBoat();
            Yacht     boat3 = new Yacht();
            //creat a list of boat
            var boats = new List <Watercraft>();

            boats.Add(boat1);
            boats.Add(boat2);
            boats.Add(boat3);
            //loop over the list with a foreach and call method Drive() for each one
            foreach (var boat in boats)
            {
                boat.Drive();
            }
            //--------------------------------------------------------------------------
        }
        static void Main()
        {
            var car1 = new HondaCivic();
            var car2 = new BMW(true);
            var car3 = new NissanLeaf(true);

            var Cars = new List <Car>();

            Cars.Add(car1);
            Cars.Add(car2);
            Cars.Add(car3);

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

            var plane1 = new WrightFlyer();
            var plane2 = new SupermarineSpitfire();
            var plane3 = new BlériotXI();

            var planes = new List <Aircraft>();

            planes.Add(plane1);
            planes.Add(plane2);
            planes.Add(plane3);

            foreach (var plane in planes)
            {
                plane.Flying();
            }

            var boat1 = new FishingBoat();
            var boat2 = new Canoe();
            var boat3 = new HouseBoat();

            var boats = new List <Watercraft>();

            boats.Add(boat1);
            boats.Add(boat2);
            boats.Add(boat3);

            foreach (var boat in boats)
            {
                boat.Driving();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Car car = new NissanLeaf();

            car.GetGas(0); //What do I pass here?  It's confusing for the caller.
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Car car = new NissanLeaf();

            car.GetGas(0); //What do I pass here?  It's confusing for the caller.
        }