Exemplo n.º 1
0
 private void button4_Click(object sender, EventArgs e)
 {
     arrayAnimal = new Animal[5];
     arrayAnimal[0] = new Cat("小花");
     arrayAnimal[0].ShoutNum = 10;
     arrayAnimal[1] = new Dog("阿毛");
     arrayAnimal[2] = new Dog("小黑");
     arrayAnimal[3] = new Cat("嬌嬌");
     arrayAnimal[4] = new Cat("咪咪");
 }
        public static Animal CreateAnimal(string animalCategory, string animalName,int shoutNumber)
        {
            Animal result=null;
            switch (animalCategory)
            {
                case "貓":
                    result = new Cat(animalName);
                    break;
                case "狗":
                    result = new Dog(animalName);
                    break;
                case "羊":
                    result = new Sheep(animalName);
                    break;
            }
            result.ShoutNum = shoutNumber;

            return result;
        }
Exemplo n.º 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     Animal cat = new Cat("小咪");
     cat.ShoutNum = 5;
     MessageBox.Show(cat.Shout());
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Cat cat = new Cat("Tom");
            Mouse mouse1 = new Mouse("Jerry");
            Mouse mouse2 = new Mouse("Jack");
            cat.CatShout += new Cat.CatShoutEventHandler(mouse1.Run);
            cat.CatShout += new Cat.CatShoutEventHandler(mouse2.Run);

            cat.Shout();

            Console.Read();
        }