Wednesday, February 19, 2014

Difference between Events and Delegates

Events are basically actions raised by an object when some condition met.
Like In stock class there is a property named Limit, and it raised an notification when it reaches certain limit. This notification is done by events


Delegate is more generic term which is similar to a pointer to a function.
They are generally used as a input parameter. In particular they are perfect way to implement Strategy patternFor example, if I want to sort a List of objects, I can provide a Compare strategy to the method to tell the implementation how to compare two objects.