Before reading this article, please go through the following articles:
- Object Oriented Programming Using C#: Part 1
- Object Oriented Programming Using C#: Part 2
- Object Oriented Programming Using C#: Part 3
- Object Oriented Programming Using C#: Part 4
- Object Oriented Programming Using C#: Part 5
- Object Oriented Programming Using C#: Part 6
- Object Oriented Programming Using C#: Part 7
- Object Oriented Programming Using C#: Part 8
- Object Oriented Programming Using C#: Part 9
- Object Oriented Programming Using C#: Part 10
- Learn OOP Interface Using C#
- Learn Object Oriented Programming Using C#: Part 12
Delegates
Dear reader, today we will discuss another important component of OOP, which is delegates. It's the modern approach to call methods. Using that approach you can call any method with the same signature as the delegate. So we can say that a delegate is the launching pad for methods; any method can be launched that matches the pattern. Or a Delegate is a class. When you create an instance of it, you pass in the function name (as a parameter for the delegate's constructor) to which this delegate will refer.
In simple words, a delegate is a type that safely encapsulates a method; a delegate is a pointer to a method. Just like you can pass a variable by reference, you can pass a reference to a method. Delegates are often used to implement callbacks and event listeners. A delegate does not need to know anything about the classes or methods it works with.
A Delegate consists of the following three parts:
- Declare a Delegate
- Instantiate the Delegate
- Execute the Delegate

Simple Example 1:
Output:
Block A:
- In this sessoion we have defined a delegate with the name Delegate_Pro with two parameters.
Block B:
- In this sessoion we have defined the method totalcost with parameters.
- In the implementation of that method we have the sum the two values and return that.
Block C:
- First we have defined the object of the delegate passing method as the parameter.
- Then we will input two parameters from the user and save them in two variables.
- Now we will activate the delegate using the object we created and save the result in another variable.
- In the end we will show the result in the console.
Events
A hook on an object where the code outside of the object can say "When that something happens, that fires this event, please call my code".
Simple Example 2:
using System;
using System.Collections.Generic;




Soha SrawiPosted Dec 4, 2016, 4:06 AM
Its a great amazing articles many thanks Naveed Zaman ,i am from jordan,petra
Naveed ZamanPosted Jul 10, 2013, 3:31 AM
thanks for your words rizwan my email is [email protected]
Syed RizwanPosted Jul 10, 2013, 2:37 AM
can i get your email address
Syed RizwanPosted Jul 10, 2013, 2:36 AM
May God gives you more knowledge
Syed RizwanPosted Jul 10, 2013, 2:34 AM
Bundle of thanks / appreciated for sharing OOP Concept i visited many sites but your way of talking is excellent and cool
Naveed ZamanPosted Jun 25, 2013, 5:21 AM
thanks alot
Rohatash KumarPosted Jun 24, 2013, 11:44 PM
Good article. Naveed