---
title: "Delegates"  
description: "Delegate is type-safe object which can point to method or multiple methods (Multicasting) of application."  
author: "Anonymous User"  
published: 2010-07-23  
updated: 2020-03-17  
canonical: https://www.mindstick.com/articles/20/delegates  
category: ".net"  
tags: [".net"]  
reading_time: 1 minute  

---

# Delegates

Delegate is type-safe object which can point to method or multiple methods (Multicasting) of application.

To define delegate we use keyword ‘Delegate’. While defining delegate we need to keep in mind that return type, arguments should be same as the return type and arguments of methods to which it is going to point to.

## Example

```
//defining delegatepublicdelegatevoidDelegates(int x,int y);public class clsNew    {        //methods delegate will point to.        public static  void Add(int x, int y)        {            MessageBox.Show("Sum:" + (x + y).ToString());        }        public static  void Mul(int x, int y)        {            MessageBox.Show("Product:" + (x * y).ToString());        }    }         //using delegate  private void btnAdd_Click(object sender, EventArgs e)        {       //creating delegate del which is pointing to Add() method of clsNew class            Delegates del= new Delegates(clsNew.Add);           //actually this is pointing to add() method              del(Convert.ToInt32(txtNum1.Text), Convert.ToInt32(txtNum2.Text));        }
```

\

![Delegates](https://www.mindstick.com/mindstickarticle/943feeab-a366-454f-b46c-98538c55b6b6/images/cee038b9-b7c0-445c-bfa1-b7e7325c7d80.png)

```
        private void btnMul_Click(object sender, EventArgs e)        {           //creating delegate del which is pointing to Mul() method of clsNew class            Delegates del = new Delegates(clsNew.Mul);         //actually this is pointing to Mul() method                del(Convert.ToInt32(txtNum1.Text), Convert.ToInt32(txtNum2.Text));        }
```

##### ![Delegates](https://www.mindstick.com/mindstickarticle/943feeab-a366-454f-b46c-98538c55b6b6/images/281f2182-7d94-43a6-8ff1-239a5a595fa2.png)

##### Ability of Multicasting

Delegates can point to more than one methods but the return type of those

methods should be void.

```
private void btnBoth_Click(object sender, EventArgs e)        {        //delegate pointing to Add() method            Delegates del= new Delegates(clsNew.Add);        //also pointing to Mul() method at the same time            del+= new Delegates(clsNew.Mul);      //this will invoke both Add() and Mul() method simultaneously.    del(Convert.ToInt32(txtNum1.Text), Convert.ToInt32(txtNum2.Text));        }
```

![Delegates](https://www.mindstick.com/mindstickarticle/943feeab-a366-454f-b46c-98538c55b6b6/images/bbe8a2f6-098d-48de-aab9-7b53946a579f.png)![Delegates](https://www.mindstick.com/mindstickarticle/943feeab-a366-454f-b46c-98538c55b6b6/images/a41b0534-f4b2-43de-bda7-e75d46d17e10.png)

---

Original Source: https://www.mindstick.com/articles/20/delegates

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
