-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
51 lines (35 loc) · 1.2 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Linq;
using System.Collections.Generic;
namespace Garage {
public class Program
{
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());
}
}
}