.net - Are delegates and callbacks the same or similar? -


are delegates same thing callbacks? or related somehow?

a "callback" term refers coding design pattern, available in language has function pointers, or analogue function pointers (which kinda delegate is)

in pattern, pass pointer function function, within called function, can "call back" function passed it. in way can control large chunk of internal behavior of method outside method, passing pointers different "callback" function each time call it... example of callback when have sorting algorithm has passed pointer function "compare" arbitrary pair of objects in list sorted, determine goes before other. on 1 call sort method, might pass callback function compares object name, , time pass function compares object weight, or whatever...

a delegate, otoh, specific .net type acts signature-specific container function pointer... in .net managed code, delegates way create , use function pointer. in .net callback, in fact passing delegate... delegates can used in other scenarios besides callbacks. (specifically, delegates can used implement multi-threading .net thread pool)

callbacks used implement "observer" pattern (implemented in .net using events, special type of delegate)


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -