Stuck in Delegates and Events concept, what are the differences and when do we use them?
-
When I read about
delegate
, I can figure out what that is and when we use that. But when I read aboutevent
, I mix things up and cannot find out how to understand the real difference and exact use of that in my codes. Every time I read aboutevent
, it gets more blur in my mind! Can you please explain that in a simple way? Thanks :) -
When I read about
delegate
, I can figure out what that is and when we use that. But when I read aboutevent
, I mix things up and cannot find out how to understand the real difference and exact use of that in my codes. Every time I read aboutevent
, it gets more blur in my mind! Can you please explain that in a simple way? Thanks :)A
delegate
is like a function pointer, andevent
is like a function. When anevent
is raised, it calls eachdelegate
that is attached to it.Events
are generic in that they can acceptdelegates
that point to any function, as long as thedelegates
' signatures match the signature of theevent
.Events
are points of attachment fordelegates
to receive calls from an object.The difficult we do right away... ...the impossible takes slightly longer.