Delegate

Why Trust Techopedia

What Does Delegate Mean?

A delegate is an object-oriented, managed, secure and type-safe function pointer in the .NET framework. A delegate signature includes its name, return type and arguments passed to it. Rather than passing data, a delegate passes a method to another method. Delegates are used in many contexts, including implementing callbacks and event handlers, entry thread points and multiple types of method specifications. Because a delegate does not know the class of a referenced object, it is used for anonymous invocation.

Advertisements

Techopedia Explains Delegate

A delegate’s main purpose is linking the delegate object to the caller, which means that the called method reference does not require specification at compile time. Delegates play a vital role in the event driven programming model, where event handlers are added to user interface (UI) controls.

Delegate types are:

  • Single-cast: Points to a single method
  • Multicast: Refers to multiple methods, each with the same signature and only includes methods returning void to avoid exception during runtime

Other delegate features are as follows:

  • They execute under caller, versus declarer, permissions.
  • Delegate objects are immutable.
  • Its default access modifier is private (internal) or public.
  • A delegate may be used after instantiation only.
  • Delegates may be declared as nested types with accessibility modifiers for their containing class or struct. In the event of failure during delegate method execution, the thrown exception is passed back to the delegate’s caller, and further invocations are stopped.

Advertisements

Related Terms

Margaret Rouse
Technology Specialist
Margaret Rouse
Technology Specialist

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.