---
title: "What is a delegate in c# and why do we are use delegate in C# programming?"  
description: "What is a delegate in c# and why do we are use delegate in C# programming?"  
author: "Ravi Vishwakarma"  
published: 2021-08-23  
updated: 2021-08-23  
canonical: https://www.mindstick.com/forum/156713/what-is-a-delegate-in-c-sharp-and-why-do-we-are-use-delegate-in-c-sharp-programming  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# What is a delegate in c# and why do we are use delegate in C# programming?

What is a [delegate in c#](https://www.mindstick.com/forum/33917/how-to-callback-operation-using-delegate-in-c-sharp) and why do we are use delegate in [C# programming](https://www.mindstick.com/forum/156714/what-is-a-sealed-class-in-c-sharp-programming-and-why-do-we-use-this-class-in-opps)?

## Replies

### Reply by Ashutosh Kumar Verma

**[Delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp) in c#** C# delegate is like reference type variable which holds reference of a method. In runtime, this reference can change. All delegate is derived from System.Delegate class. 'delegate' keyword is used to declare a delegate.

**syntax** of delegate in c#

## <access modifier> delegate <return type> <delegate_name>(<parameters>)

## Use of delegate

In delegate we can pass function like a parameter. To holds the reference of any method by delegate which has same return type and parameter as like delegate. In other word 'we can use delegate to hold the reference of that method which has same return type and parameter as delegate has.'

## example

using System;

class Example

{ public delegate void Demo(int a, int b); //declare a delegate.

static void main(String arg[])

{

Demo d= Add;

d(10,20);

Console.ReadLine();

}

public static void Add(int x, int y) // method has same return type and parameter

{

Console.WriteLine('Sum is '+ (x+y));

}

}


---

Original Source: https://www.mindstick.com/forum/156713/what-is-a-delegate-in-c-sharp-and-why-do-we-are-use-delegate-in-c-sharp-programming

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
