static void Main(string[] args) { IFly popper = new Penguin("Spheniscidae", 8); Parrot tweety = new Parrot("Tweety", "yellow"); Squirrel squirrel = new Squirrel(); Dictionary <string, List <IFly> > FlyingCreatures = new Dictionary <string, List <IFly> >(); List <IFly> birds = new List <IFly>() { popper, tweety }; // birds.Add(popper); // birds.Add(tweety); FlyingCreatures["birds"] = birds; FlyingCreatures["non-birds"] = new List <IFly>() { squirrel, tweety }; //Itterates over object keys and values calling each pair 'types' foreach (KeyValuePair <string, List <IFly> > types in FlyingCreatures) { System.Console.WriteLine(types.Key); //Itterates over inner lists for (int i = 0; i < types.Value.Count; i++) { types.Value[i].Fly(); } } }
static void Main(string[] args) { FlowerShop myShop = new FlowerShop(); List <Rose> bouqetOfRoses = myShop.createRoseBouqet(); bouqetOfRoses.ForEach(rose => Console.WriteLine(rose.species)); Bat Barty = new Bat() { name = "Barty", maximumHeight = 100, speed = 30, hasFeathers = false, isVampire = true, }; Barty.fly(); Penguin Penny = new Penguin() { name = "Penny", isMammal = false, isSaltWater = true, maxDepth = 50 }; Penny.swim(); Penny.walk(); }