---
title: "Delegate in C#.Net"  
description: "When we make an object of a class then we can access all function of a class and Base class functions too. Here we can see that a user can simple make"  
author: "AVADHESH PATEL"  
published: 2012-07-09  
updated: 2017-11-30  
canonical: https://www.mindstick.com/articles/954/delegate-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Delegate in C#.Net

When we make an object of a class then we can access all function of a class and [Base class](https://www.mindstick.com/blog/116/base-class-initilization) functions too. Here we can see that a user can simple make an object of a class and access all information of class. But in real word this is drawback of an object. \

For example we are an account holder of a bank, and we have [permission](https://answers.mindstick.com/qa/33390/how-to-enable-api-access-in-salesforce-by-permission-set) to access all information, like other account holder’s details, bank deposited details and etc. think what [happens if](https://yourviews.mindstick.com/view/88489/what-happens-if-ai-goes-offline-for-a-day) bank provide all accessibly to account user…….

Through delegate we provide limited [accessibility](https://www.mindstick.com/interview/209/describe-the-accessibility-modifier-protected-internal) to user.

##### Delegate in technical Word …

- Delegate is a keyword that behaves runtime as a class.
- Class’s object has [reference](https://www.mindstick.com/forum/34619/call-by-value-and-call-by-reference) of a class, but delegate’s object has reference of a function.
- Through delegate we can break accessibility of all function.
- Through delegate we can save time.
- Through delegate we can achieve dynamic method invocation.
- Through delegate we called planed function.
- It absolution support type softy.
- Delegate is similar function [pointer in c](https://answers.mindstick.com/qa/104680/what-is-a-pointer-in-c).
- Delegate’s object data type not fixed.
- Through delegate object we can call any function from any class but both data type and signature must be same.
- Using delegate we make [dynamic object](https://www.mindstick.com/forum/872/how-to-serialize-list-property-of-a-dynamic-object).
- Through delegate we achieve pure encapsulation.
- Simple class provides us synchronous call back. That means a class function can’t execute parallel. In other words, till one function execution not completed then we can’t call another function but delegate achieve it [Asynchronous](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) call back.
- Delegate class is [independent](https://answers.mindstick.com/qa/98599/what-is-the-longest-river-in-the-commonwealth-of-independent-states) to any class means we can declare the delegate either inside the class or [outside the class](https://www.mindstick.com/interview/2468/can-you-access-the-private-method-from-outside-the-class).

##### Example

```
delegate int ptr();     class A    {        public int show()        {            return 12;        }    }     class B    {        public int display()        {            return 15;        }    }      class Program    {        static void Main(string[] args)        {            A a = new A();            ptr k = new ptr(a.show);            Console.WriteLine(k());            Console.ReadLine();        }    }
```

\

Output

22

```
    delegate int ptr();     class A    {        public int show()        {            return 12;        }    }     class B    {        public int display()        {            return 15;        }    }      class Program    {        static void Main(string[] args)        {            //A a = new A();            //ptr k = new ptr(a.show);            //Console.WriteLine(k());             B b = new B();            ptr k = new ptr(b.display);            Console.WriteLine(k());            Console.ReadLine();        }    } 
```

\

Outout\

15

---

Original Source: https://www.mindstick.com/articles/954/delegate-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
