Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
my dear you can read this url
https://www.tutorialspoint.com/csharp/csharp_delegates.htm
A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.
n most cases, when we call a function, we specify the function to be called directly. If the class MyClass has a function named Process, we'd normally call it like this (SimpleSample.cs):
using System; namespace Akadia.NoDelegate{ public class MyClass { public void Process() { Console.WriteLine("Process() begin"); Console.WriteLine("Process() end"); } } public class Test { static void Main(string[] args) { MyClass myClass = new MyClass(); myClass.Process(); } }}
That works well in most situations. Sometimes, however, we don't want to call a function directly - we'd like to be able to pass it to somebody else so that they can call it. This is especially useful in an event-driven system such as a graphical user interface, when I want some code to be executed when the user clicks on a button, or when I want to log some information but can't specify how it is logged.
A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. Delegates are especially used for implementing events and the call-back methods.
For further understanding, follow this tutorial.
Deletages are like function pointers in c++, although they are type-safe and secure. In a more basic term, a Delegate is a function that you passed as a parameter.
A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.
Delegates are used to pass methods as arguments to other methods. Event handlers are nothing more than methods that are invoked through delegates. You create a custom method, and a class such as a windows control can call your method when a certain event occurs.
Impersonation enables ASP.NET to execute code and access resources in the context of an authenticated and authorized user, but only on the server where ASP.NET is running. To access resources located on another computer on behalf of an impersonated user requires authentication delegation (or delegation for short).
C# is similar to a function pointer C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object.
delgates are .net objects to which event handlers can be attached.When event of the delegate type is raised,the event handler wil be executed
Passing Function as Parameter will be called as delegate
A delegate is a reference type variable that holds the reference to a method. This reference can be changed at runtime and delegates are especially used for implementing events and the call-back methods. It can be said that all delegate are implicitly derived from the System.Delegate class
Delegates are objects, used as methods similar to function pointers but they are references based.