How delegates work (in the background)?

前端 未结 6 565
温柔的废话
温柔的废话 2020-12-10 06:16

How do delegates work in c# behind the scenes and how can they be used efficiently?

EDIT: I know how they work on the surface(they are basically function pointers a

6条回答
  •  失恋的感觉
    2020-12-10 06:47

    C# compiler generates a full blown class when you create a delegate. This class holds a list of function references, as Konrad mentioned. The nice thing about delegates is that they provide you with easy way to execute the task asynchronously with notification callback. What this means is that you can be notified when your background operation completes. Threadpool doesn't provide this feature. Delegates are a vast topic and I find Jeff Richter's (CLR via C#) and Albahari (C#3) books of particular help.

提交回复
热议问题