What is delegate in .NET?
Answers (1)
Add AnswerA delegate is a type in the.NET environment that defines a method signature and can provide a function as a parameter. To put it simply, a delegate is a. NET object that links to a method that meets its specific signature.
public delegate void MyDelegate(string msg); // declare a delegate // set target method MyDelegate del = new MyDelegate(MethodA); // or MyDelegate del = MethodA; // or set lambda expression MyDelegate del = (string msg) => Console.WriteLine(msg); // target method static void MethodA(string message) { Console.WriteLine(message); }