Please Give a detailed explanation of Delegates in C#
Give a detailed explanation of Delegates in C#
1740
12-Dec-2019
Nishi Tiwari
13-Dec-2019Delegates can be defined as an object refer to a methods or we can say that it is a referenced type variable that holds the reference of a method. It is similar to pointer function in C and C++, but is object-oriented, secure and type safe than function pointer. It is used for implementing events and call back methods. For example, if we click on Button on forms (windows application), then program would call a specific method or it is a type reference to a method with particular parameter list and return type and then calls methods when it is needed. All delegates are implicitly derived from System.Delegates class.
For declaring delegates following syntax is used
After declaring delegates objects are instanced with new keyword.
Syntax for instantiating delegates
Example
Output: