Why do we need C# delegates

前端 未结 8 612
遥遥无期
遥遥无期 2020-12-22 19:47

I never seem to understand why we need delegates? I know they are immutable reference types that hold reference of a method but why can\'t we just call the method directly,

相关标签:
8条回答
  • 2020-12-22 20:42
    1. Delegates supports Events
    2. Delegates give your program a way to execute methods without having to know precisely what those methods are at compile time
    0 讨论(0)
  • 2020-12-22 20:45

    Think of C/C++ function pointers, and how you treat javascript event-handling functions as "data" and pass them around. In Delphi language also there is procedural type. Behind the scenes, C# delegate and lambda expressions, and all those things are essentially the same idea: code as data. And this constitutes the very basis for functional programming.

    0 讨论(0)
提交回复
热议问题