Why do we need C# delegates

前端 未结 8 652
遥遥无期
遥遥无期 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: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.

提交回复
热议问题