Share via


Callback Function Usage

Delegates, Interfaces and Events allow you to provide callback functionality. Each type has its own specific usage characteristics that make it better suited to particular situations.

Events

Use an event if the following are true:

  • A method signs up for the callback function up front, typically through separate Add and Remove methods.
  • Typically, more than one object will want notification of the event.
  • You want end users to be able to easily add a listener to the notification in the visual designer.

Delegates

Use a delegate if the following are true:

  • You want a C language style function pointer.
  • You want a single callback function.
  • You want registration to occur in the call or at construction time, not through a separate Add method.

Interfaces

Use an interface if the callback function requires complex behavior.

See Also

Design Guidelines for Class Library Developers