Delegates in C#
Delegates are nothing but it is a reference to the methods and Delegate is a keyword used to create a method object and it will help us to pass the method as parameters.
Declarations
- public delegate TypeOfDelegate Delegate_Name();
Examples
- public delegate string myDelegate(string FirstName, string LastName);
I would like to share the Type of Delegates in C# and please refer the details below,
- Single Delegate
- Multicast Delegate
- Generic Delegate
Sample Programs
- public delegate string myDelegate(string FirstName, string LastName);
- public class Personal {
- public static string myDelegate(string FirstName, string LastName) {
- return FirstName + "" + LastName + "";
- }
- static void Main(string[] args) {
- string FirstName = "Manikandan";
- string LastName = "M";
- //Creating the Delegate object
- myDelegate delObj = new myDelegate(myDelegate);
- //use a delegate for processing
- string res = delObj(FirstName, LastName);
- Console.WriteLine("Full Name :" + res);
- Console.ReadLine();
- }
- }
- //Output: Manikandan M
Conclusion
This article could help you to understand the delegates in C# using simple Programming.

Join the conversation! Your thoughts help the community grow.