示例#1
0
        static void Main(string[] args)
        {
            SuperMan  Clark  = new SuperMan("Clark", 39);
            SpiderMan Peter  = new SpiderMan(3, "Peter", 29);
            Flash     gordon = new Flash(9, "Gordon", 31);

            ISuperHero[] SuperHeroes = new ISuperHero[] { Clark, Peter, gordon };

            foreach (ISuperHero item in SuperHeroes)
            {
                ActiveHero(item);
            }
        }
示例#2
0
        static void GetMoreHeroData(ISuperHero hero)
        {
            SuperMan superman = hero as SuperMan;

            if (superman != null)
            {
                Console.WriteLine(superman.Speed);
            }
            SpiderMan Spider = hero as SpiderMan;

            if (Spider != null)
            {
                Console.WriteLine(Spider.WebLeft);
            }
            Flash Flashy = hero as Flash;

            Console.WriteLine(Flashy.Voltage);
        }