예제 #1
0
파일: Form1.cs 프로젝트: niuniuliu/CSharp
 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("咪咪");
 }
예제 #2
0
        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;
        }
예제 #3
0
파일: Form1.cs 프로젝트: skmygdrs/jgy_code
 private void button1_Click(object sender, EventArgs e)
 {
     Animal cat = new Cat("小咪");
     cat.ShoutNum = 5;
     MessageBox.Show(cat.Shout());
 }
예제 #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();
        }