We can call callback methods using delegates. For eg,
public delegate bool ContinueProcessing();
// later in code we can write ,
ContinueProcessing cp = new ContinueProcessing(IsDataAvailable);
cp += new ContinueProcessing(IsTransactionComplete);
//later in code defination of methods
bool IsDataAvailable() { return true; }
bool IsTransactionComplete() { return true; }
cp.Invoke() ;
The above call will call two boolean method one after the other. Why we need "Events" ? What is the purpose of "Events" ?
Events are callbacks where you can have multiple subscribers who don't interfere with each other and can't call each other.
Delegates provide the encapsulation of "this is the action I want to take" and events provide the encapsulation of the pub/sub model.
See my article on events for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With