namespace 关于一杯水的委托
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IDrink mydrink = new IDrink("凉开水", "");
mydrink.Idrink += new IDrink.Drink(wateronly); //这个 +=是什么意思
mydrink.execu();
}
private void wateronly(string water, string mainthing)
{
MessageBox.Show("你喝了" + water);
MessageBox.Show("你加了" + mainthing);
}
}
}
namespace 关于一杯水的委托
{
class IDrink
{
public string _water = "";
public string _mainthing = "";
public delegate void Drink(string water, string mainthing);
public Drink Idrink = null;
public IDrink(string water, string mainthing)
{
_water = water;
_mainthing = mainthing;
}
public void execu()
{
MessageBox.Show("取出杯子");
Idrink(_water, _mainthing);
MessageBox.Show("享用中");
MessageBox.Show("清洗并归放原位");
}
}
}