static void Main(string[] args) { Cow cow = new Cow(); Dog dog = new Dog(); Philosopher philosopher = new Philosopher(); cow.Speak(); dog.Speak(); philosopher.Speak(); philosopher.Think(); Console.WriteLine("__________________________\n"); ISpeak speaker = new Dog(); speaker.Speak(); speaker = new Philosopher(); speaker.Speak(); Console.WriteLine("__________________________\n"); // cow = dog; No can do :( // speaker.Think(); No can do ((Philosopher)speaker).Think(); Console.ReadLine(); }
static void Main(string[] args) { ISpeak speaker = new Philosopher(); Console.WriteLine(speaker.Speak()); ((Philosopher)speaker).Think(); bool _loop = true; string _userChoise; while (_loop == true) { Console.WriteLine("Læs tankerne på Hund tryk: 1 Læs tankerne på Ko tryk: 2 Læs tankerne på Frø tryk: 3 Afslut tryk: 9"); _userChoise = Console.ReadLine(); if (_userChoise == "1") { speaker = new Dog(); Console.WriteLine(speaker.Speak()); } else if (_userChoise == "2") { speaker = new Cow(); Console.WriteLine(speaker.Speak()); } else if (_userChoise == "3") { speaker = new Frog(); Console.WriteLine(speaker.Speak()); } else if (_userChoise == "9") { _loop = false; } else { Console.WriteLine("Fejl, vælg 1, 2, 3 eller 9"); } } }
static void Main(string[] args) { List <ISpeak> list = new List <ISpeak>(); list.Add(new Cow()); list.Add(new Dog()); list.Add(new Philosopher()); foreach (ISpeak s in list) { s.Speak(); } ISpeak speeker = new Philosopher(); speeker.Speak(); // speeker.Think(); won't work because ISpeak does not have Think method Philosopher speeker2 = new Philosopher(); speeker2.Think(); }