What is the difference between delegate and events

Q

What is the difference between delegate and events?

✍: Guest

A

ć Actually events use delegates in bottom. But they add an extra layer on the delegates, thus forming the publisher and subscriber model.
ć As delegates are function to pointers they can move across any clients. So any of the clients can add or remove events, which can be pretty confusing. But events give the extra protection by adding the layer and making it a publisher and subscriber model.
Just imagine one of your clients doing this
c.XyzCallback = null
This will reset all your delegates to nothing and you have to keep searching where the error is.

2007-10-23, 5770👍, 0💬