Skip to main content

learn Delegate function in C#

1 advantages for delegate function
1.1 decouple the caller class and callee class.They don't need know any internal detail about each other.
1.2 pass some values and handle from caller to callee. Not for from callee to caller!!!

2 sample code
class Callee
{
private Fucntion Dosomething()

{
this.NotifyDelegate();
}
public delegate void Notify();
//declare a delegate function event instance
public event Notify NotifyDelegate;
}
class Caller
{
Callee instanceCallee = new Callee();
Callee.NotifyDelegate + = new Notify(NotifyFromCallee)
private void Function()
{
instanceCallee.Dosomething();
}
private void NotifyFromCallee()
{
//blah, blah, blah
}
}

Comments

Popular posts from this blog

home routine dairy

handyman workshop fixed bosch dishwasher hinge cover took off the rusted laundry tap

sold prado today

fixed a cold case of slowness internet connection

mtu 1480 to 1492