文档库 最新最全的文档下载
当前位置:文档库 › 添加小狗代码txt

添加小狗代码txt

using System;
using System.Collections.Generic;
using https://www.wendangku.net/doc/ac18054762.html,ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
petmypet=new pet;

public Form1()
{
InitializeComponent();
}

private void btnDog_Click(object sender, EventArgs e)
{
mypet.Animals.Add(new Dog(txtName.Text));
lblShow.Text += string.Format("\n添加 Dog:{0}成功",txtName.Text);

}

private void btnSmallDog_Click(object sender, EventArgs e)
{
mypet.Animals.Add(new SmallDog(txtName.Text));
lblShow.Text += string.Format("\n添加 SmallDog:{0}成功",txtName.Text);
}

private void btnCat_Click(object sender, EventArgs e)
{
mypet.Animals.Add(new Cat(txtName.Text));
lblShow.Text += string.Format("\n添加 Cat:{0}成功",txtName.Text);
}

private void btnFeed_Click(object sender, EventArgs e)
{
lblShow.Text=mypet.FeedTheAnimals();
}
public abstract class Aniaml
{
protected string name;
public Aniaml(string name)
{
https://www.wendangku.net/doc/ac18054762.html,=name;
}
public abstract string Eat();
}
public class Dog:Aniaml
{
public override string Eat()
{
return string .Format("{0}:我是Dog,我要吃骨头!",name);
}

}
public class cat:Aniaml
{
public cat()
}
}

相关文档