static void Main(string[] args) { SuperMan superman = new SuperMan("Superman", 34, 220); SpiderMan spiderman = new SpiderMan("Spiderman", 41, 137); Flash flash = new Flash("Flash", 29, 1000); ISuperHero[] _heroes = { superman, spiderman, flash }; foreach (ISuperHero hero in _heroes) { ActivateHero(hero); Console.WriteLine(); GetMoreHeroData(hero); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"{CreateHero("Superman").GetName()}"); Console.WriteLine(); Console.WriteLine($"{CreateHero("Spiderman").GetName()}"); Console.WriteLine(); Console.WriteLine($"{CreateHero("Flash").GetName()}"); Console.ReadKey(); }
static Human CreateHero(string nameHero) { SpiderMan Spiderman; SuperMan Superman; Flash Flash; switch (nameHero) { case "Spiderman": return(Spiderman = new SpiderMan("Spiderman1", 47, 281)); case "Superman": return(Superman = new SuperMan("Superman1", 22, 600)); case "Flash": return(Flash = new Flash("Flash1", 43, 1000)); } return(null); }