A delegate in C# is a type that can refer to a method. The concept of delegate in C# is similar to the pointer to function in C++, but delegate in C# is said to be more safe and secure.
To use a delegate, you need to declare it first. In the following example, we declare a delegate called Mydelegate to point to a method call printName(String). The method that is referred to by the delegate must be defined in the same structure as delegate (return type, number of arguments, and types of arguments must be the same).
delegate void Mydelegate(string Name); //declare a delegate
//with return type void and one string argument
static void Main(string args)
Mydelegate m= new Mydelegate(Program.printName);//refer to the printName method
m("Dara Yuk"); //call the method
static void printName(string Name)//declare a method with
//return type void and one string argument to match the delegate
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: