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
The first part of the question is relatively easy: delegates store a list of function pointers. If you invoke a delegate, it calls all the function pointers in that internal list. Adding and removing a receiver (via Delegate.Combine and Delegate.Remove) amounts to adding to and removing from that list.
For more low-level information, refer to ECMA-335 (the CLI standard), section II.14.5 (Method pointers) and II.14.6 (Delegates). In particular, note that a delegate consists of an instance pointer (of type System.Object) and a method pointer (of type System.IntPtr). A method pointer can be obtained (in CIL) via the ldftn or ldvirtftn (for virtual function calls) instructions.
These two pieces of information identify any method.
how can they be used efficiently?
What do you mean by that? Do you know about events or is your question more specialized?