Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 3
    Personally, it feels to me that using delegates split up your code into units and make it tons more manageable. Great mechanism to use in conjunction with unit testing if most of your methods have the same signature pattern Commented Jul 11, 2014 at 11:22
  • 117
    "Please feel free to put any method that match this signature here and it will be called each time my delegate is called" -> you made my day, great explanation! Commented Sep 13, 2014 at 14:42
  • 2
    Also consider it as runtime dynamic binding with many of the benefits of compile time static binding. Invocation of a delegate is orders of magnitude faster than the reflection invoke alternative. Additionally if a function signature changes such that it no longer matches the delegate this results in a compile time error which you don't get with reflection invoke. Consider for example the scenario of an MSMQ style message router. The Subscriber message receive functions could simply be stored in a dictionary of message routing key and subscriber delegate pair. Commented Jan 31, 2017 at 0:40
  • 5
    Are delegates considered a form of dependency injection? Commented Mar 8, 2019 at 1:46