none
Does using Delegate calls increases performance than using Method class? RRS feed

  • Question

  • I have seen lot of developers using delegate calls rather than Method calls.

    Does anyone please let me know, why delegates are mostly used than methods and does delegates increases performance ?

    Amal Raj U

    Tuesday, February 27, 2018 11:48 AM

All replies

  • Not sure what you mean by "using delegate calls rather than method calls".

    A delegate is simply a "datatype" for a method; a kind of definition for a method that fits a particular prototype, i.e. you could define a delegate to refer to "a method that takes 1 string argument and returns an integer".

    This allows you to pass methods as arguments and use as callbacks for event handlers and so on (as described here).

    • Proposed as answer by Fei HuModerator Wednesday, February 28, 2018 9:09 AM
    Tuesday, February 27, 2018 12:33 PM
  • Does delegate callbacks improve performance ?

    Amal Raj U

    Tuesday, February 27, 2018 12:45 PM
  • Its nothing to do with performance. Using a delegate is no different to calling any other method. A delegate IS a reference to a method.

    (Though technically there is an object that sits between the caller and method code that allows for multi-casting, i.e. chaining multiple methods on to a single delegate, but I doubt there would be any appreciable difference in performance in general usage)

    • Proposed as answer by Cor Ligthert Tuesday, February 27, 2018 1:01 PM
    Tuesday, February 27, 2018 12:58 PM
  • Hello Amal,

    >>Does anyone please let me know, why delegates are mostly used than methods and does delegates increases performance?

    Delegate are used for providing a mechanism for callbacks. just like method pointer in C++. In fact delegate is class type and it contains some fields inside.

    _methodPtr is used to store callback method, _invocationList is delegate array type and it is used to build delegate chain. when you invoke delegate these method will be executed one by one, it doesn't  improve performance at all.

    If you have any issues with delegate, do not hesitate to let us know.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 28, 2018 9:09 AM
    Moderator