---
title: "Give a detailed explanation of Delegates in C#"  
description: "Give a detailed explanation of Delegates in C#"  
author: "Anonymous User"  
published: 2019-12-12  
updated: 2019-12-12  
canonical: https://www.mindstick.com/forum/155584/give-a-detailed-explanation-of-delegates-in-c-sharp  
category: ".net"  
tags: [".net", "delegates"]  
reading_time: 2 minutes  

---

# Give a detailed explanation of Delegates in C#

Please Give a [detailed explanation](https://answers.mindstick.com/qa/94806/i-want-to-learn-android-app-development-can-anyone-give-a-detailed-explanation-of-how-i-should-start) of [Delegates in C#](https://www.mindstick.com/forum/33765/delegates-in-c-sharp)

## Replies

### Reply by Nishi Tiwari

**Delegates** 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](https://www.mindstick.com/forum/155583/what-are-namespaces-in-c-sharp)** 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

```
Delegate <return type> delegate_name <parameter list>
```

After declaring delegates objects are instanced with new keyword.

Syntax for **instantiating** delegates

```
[delegate_name]  instance_name=new [delegate_name] (calling_method_name);
```

## Example

```
using System;

delegate int NumberChanger(int n); namespace DelegateAppl {
   class TestDelegate {       static int num = 10;
      
public static int AddNum(int p) {          num += p;
         return num;
      }
      public static int MultNum(int q) {
         num *= q;
         return num;
      }
      public static int getNum() {
         return num;
      }
      static void Main(string[] args) {
         //create delegate instances
         NumberChanger nc1 = new NumberChanger(AddNum);
         NumberChanger nc2 = new NumberChanger(MultNum);

         //calling the methods using the delegate objects
         nc1(25);
         Console.WriteLine("Value of Num: {0}", getNum());
         nc2(5);
         Console.WriteLine("Value of Num: {0}", getNum());
         Console.ReadKey();
      }
   }
}
```

## Output:

```
Value of Num: 35
Value of Num: 175
```

![Give a detailed explanation of Delegates in C#](https://www.mindstick.com/mindstickforums/3a46c848-429a-4263-930b-6b78aacc813c/images/7527ed9c-9d2e-4691-aaad-1cccd3b1e1a3.jpeg)

![Give a detailed explanation of Delegates in C#](https://www.mindstick.com/mindstickforums/3a46c848-429a-4263-930b-6b78aacc813c/images/2955ac8c-5fbf-4543-a579-bbf0ad5203de.jpeg)


---

Original Source: https://www.mindstick.com/forum/155584/give-a-detailed-explanation-of-delegates-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
