1. Simple delegate (tom eats watermelon ......)
Code
Namespace _ 24. Delegate _ 1 _
{
Delegate void Eat (string food );
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Static void xwEat (string food)
{
MessageBox. Show ("Xiao Wang eat" + food );
}
Private void Form1_Load (object sender, EventArgs e)
{
Eat xw = new Eat (xwEat );
Xw ("watermelon ");
// XwEat ("watermelon ");
}
}
}
2. Continue the above expansion
Code
Namespace _ 24. Delegate _ 1 _
{
Delegate void Eat (string food );
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Static void xwEat (string food)
{
MessageBox. Show ("Xiao Wang eat" + food );
}
Static void xlEat (string food)
{
MessageBox. Show ("Xiao Li eat" + food );
}
Static void xzEat (string food)
{
MessageBox. Show ("Xiao Zhao eat" + food );
}
Private void Form1_Load (object sender, EventArgs e)
{
Eat xw = new Eat (xwEat );
Eat xl = new Eat (xlEat );
Eat xz = new Eat (xzEat );
Xw ("watermelon ");
Xl ("watermelon ");
Xz ("watermelon ");
// XwEat ("watermelon ");
}
}
}
3. Continue the above expansion
Code
Namespace _ 24. Delegate _ 1 _
{
Delegate void Eat (string food );
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Static void xwEat (string food)
{
MessageBox. Show ("Xiao Wang eat" + food );
}
Static void xlEat (string food)
{
MessageBox. Show ("Xiao Li eat" + food );
}
Static void xzEat (string food)
{
MessageBox. Show ("Xiao Zhao eat" + food );
}
Private void Form1_Load (object sender, EventArgs e)
{
Eat xw = new Eat (xwEat );
Eat xl = new Eat (xlEat );
Eat xz = new Eat (xzEat );
Eat EatChain;
EatChain = xw + xl + xz;
EatChain ("watermelon ");
}
}
}
4. Continue the above expansion
Code
Namespace _ 24. Delegate _ 1 _
{
Delegate void Eat (string food );
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Static void xwEat (string food)
{
MessageBox. Show ("Xiao Wang eat" + food );
}
Static void xlEat (string food)
{
MessageBox. Show ("Xiao Li eat" + food );
}
Static void xzEat (string food)
{
MessageBox. Show ("Xiao Zhao eat" + food );
}
Private void Form1_Load (object sender, EventArgs e)
{
Eat xw = new Eat (xwEat );
Eat xl = new Eat (xlEat );
Eat xz = new Eat (xzEat );
Eat EatChain;
MessageBox. Show ("three-person meeting ");
EatChain = xw + xl + xz;
EatChain ("watermelon ");
MessageBox. Show ("John goes out to answer the phone ");
EatChain-= xw;
EatChain ("grape ");
MessageBox. Show ("Tom comes back to eat oranges with everyone ");
EatChain + = xw;
EatChain ("orange ");
}
}
}
5. Continue the above expansion
Code
Namespace _ 24. Delegate _ 1 _
{
Delegate void Eat (string food );
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Eat eatChain = null;
EatChain + = delegate (string food)
{
MessageBox. Show ("Xiao Wang eat" + food );
};
EatChain + = delegate (string food)
{
MessageBox. Show ("Xiao Zhao eat" + food );
};
EatChain ("watermelon ");
}
}
}