Delegate (.NET)

From Wikipedia, the free encyclopedia

In computer science, delegate is a form of type-safe function pointer used in the .NET Framework technology developed by Microsoft Corporation for computer software development. Delegates specify a method to call and optionally an object to call the method on. They are used to implement callbacks and event listeners.

[edit] Implementation

Although internal implementations may vary, delegate instances can be thought of as a list of tuples of an object and a method pointer, allowing multiple delegates to be combined into a single object. As a result, delegates can support multiple event listeners. When invoking a delegate, each method in the list is called.

Delegates are more efficient than interfaces as the method pointer is calculated (if virtual) when the delegate is first assigned, rather than each time it is invoked.

[edit] See also


In other languages