Why do we need C# delegates

前端 未结 8 717
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 20:06

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:29

    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.

提交回复
热议问题