18
Reply

In which situation(s), the use of "Delegate" is a good idea?

Deepak Verma

Deepak Verma

Jul 06, 2012
30k
5

    Delegates can be used in following cases:- 1) When you want to pass the methods as a parameter 2) most important usage of delegate is event handling. Event Handlers are nothing but methods being pointed by delegates and called. 3) It can also be used in Callbacks 4) Asynchronous processing

    Anil Purswani
    July 17, 2012
    10

    In asp.net , when you want to pass some data from user control to content page

    Ramdas Chavan
    February 02, 2015
    2

    The exact situation for delegates is, passing the method as a argument. public delegate int DelegateAdd(int a,int b); class MyClass { static int function_values(int val1,int val2) { return val1+val2; } static void Main(string[] args) { //Creating the Delegate Instance Delegate_Add delObj = new Delegate_Add(DelegateAdd); Console.Write("Please Enter Values"); int v1 = Int32.Parse(Console.ReadLine()); int v2 = Int32.Parse(Console.ReadLine()); //use a delegate for processing int Result = delObj(v1,v2); Console.WriteLine ("Result :"+res); Console.ReadLine(); } }

    Rajesh Pathakoti
    July 16, 2014
    2

    There are three main uses of Delegates. 1) Delegates are used in Event handling. As Event handlers are also methods which are pointed by delegates. 2) Delegates are used when you have to pass some method as parameter. 3) Delegates are used in Asynchronous processing

    Jamil Moughal
    November 10, 2016
    1

    we should use delegate to call the event procedure.

    Pankaj Kumar Choudhary
    August 31, 2015
    1

    Passing data from user control to content page

    Ramdas Chavan
    February 02, 2015
    1

    Delegates are useful when you do want to propagate events to other objects without any relationship with them.

    Akkiraju Ivaturi
    August 23, 2012
    1

    The main use of Delegate when you need to pass the logic , When developer are not sure what logic is going to pass to complete an event or in method call. for example when in Entity Framework user call where method over an entity he need to pass logic either as lambda function. All below case stating the same 1) When you want to pass the methods as a parameter 2) most important usage of delegate is event handling. Event Handlers are nothing but methods being pointed by delegates and called. 3) It can also be used in Callbacks 4) Asynchronous processing

    anand kaurav
    January 30, 2017
    0

    The main use of Delegate when you need to pass the logic , When developer are not sure what logic is going to pass to complete an event or in method call. for example when in Entity Framework user call where method over an entity he need to pass logic either as lambda function. All below case stating the same 1) When you want to pass the methods as a parameter 2) most important usage of delegate is event handling. Event Handlers are nothing but methods being pointed by delegates and called. 3) It can also be used in Callbacks 4) Asynchronous processing

    anand kaurav
    January 30, 2017
    0

    The main use of Delegate when you need to pass the logic , When developer are not sure what logic is going to pass to complete an event or in method call. for example when in Entity Framework user call where method over an entity he need to pass logic either as lambda function. All below case stating the same 1) When you want to pass the methods as a parameter 2) most important usage of delegate is event handling. Event Handlers are nothing but methods being pointed by delegates and called. 3) It can also be used in Callbacks 4) Asynchronous processing

    anand kaurav
    January 30, 2017
    0

    The main use of Delegate when you need to pass the logic , When developer are not sure what logic is going to pass to complete an event or in method call. for example when in Entity Framework user call where method over an entity he need to pass logic either as lambda function. All below case stating the same 1) When you want to pass the methods as a parameter 2) most important usage of delegate is event handling. Event Handlers are nothing but methods being pointed by delegates and called. 3) It can also be used in Callbacks 4) Asynchronous processing

    anand kaurav
    January 30, 2017
    0

    In my opinion when i need to pass methods as a parameter.

    Sumit Joshi
    August 12, 2015
    0

    Deligate are used for creating events.1)I have used deligate while i was creating an user control in my application and to define the events of that control i have used deligate. 2)secondly the use of deligate is to call the event procedure.

    Debendra Dash
    April 19, 2015
    0

    Delegates whenever you call its always call same memory location, they didn't create new memory when you call many times. thanks

    pramod pandit
    November 10, 2014
    0

    If you need further explanation please let me know so that i will give you complete details .

    Palle Technologies
    April 02, 2014
    0

    Assume you need to create a framework which needs to call an unknown method present in an unknown class . For details better to read

    overriding-in-C-Sharp-and-internals-of-overriding

    Palle Technologies
    April 02, 2014
    0

    When you do not know what is going to happen until run time. Since delegates are of user type, and you do not know what is going to happen at run time the best practice is to return void values. This is what makes them ideal for event handling, if you need more then 1 event handled in the same action, they can be added to the delegate and fired in what ever selectable order. Also delegates can make calls to methods from other classes you do not wish to interface all the methods of. So you can select what methods are accessible.

    Juan Van
    July 17, 2012
    0

    if i am not wrong then if you have a multiple process to do in parallel then use delegate

    Kunal Vaishya
    July 10, 2012
    0