- Delegates are kind of similar to the function pointers. But they are secure and type-safe.
- A delegate instance encapsulates a static or an instance method.
- Declaring a delegate defines a reference type which can be used to encapsulate a method having a specific signature.
- Delegate is a type which holds a reference to a method.
- It is declared with a signature that shows the return type and parameters for the methods it references.
- It can hold references, only methods that match its signature.
- It is equivalent to a type-safe function pointer or callback.Declaration of Delegates:
public delegate int MyDelegate (String s);
- It is used for implementing events and the call-back methods.
- All the delegates are implicitly derived from the System.Delegate class.