Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What are Delegates?

user-image
Question added by Imran Zabih , Senior Software Engineer , Foodpanda
Date Posted: 2017/01/12
ahmad saad
by ahmad saad , Senior .net developer , Civilsoft

my dear  you can read this url

https://www.tutorialspoint.com/csharp/csharp_delegates.htm

Ismail Abd Elsalam ABD ELGHANI
by Ismail Abd Elsalam ABD ELGHANI , Software Engineering , Ekad Soft

 

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.

Muhammad Usman
by Muhammad Usman , Sr. Data Scientist , i2c

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.

https://www.youtube.com/watch?v=D2h46fvQX04

Eric Thomas Cabigting
by Eric Thomas Cabigting , IT Project Manager , Digital Qube

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.

Bart Schelkens
by Bart Schelkens , Senior .Net Developer-Analyst , Komma Board

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.

Asad Ali
by Asad Ali , Frontend Web Developer , NBTHUB

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).

Abdelfattah Abdelhamid
by Abdelfattah Abdelhamid , SENIOR .NET DEVELOPER , SENIOR .NET DEVELOPER

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.

Basem AlShabani
by Basem AlShabani , POS systems developer , GTS One

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

Mohammed Saud Alam
by Mohammed Saud Alam , Software Developer , JAL International Co

Passing Function as Parameter will be called as delegate

Pascal Oke
by Pascal Oke , Software Developer , AXA Mansard Insurance Plc

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.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.