Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The question boils down to this: the CLI (Common Language Infrastructure) specification says that delegates are reference types. Why is this so?</p> <p>One reason is clearly visible in the .NET Framework today. In the original design, there were two kinds of delegates: normal delegates and "multicast" delegates, which could have more than one target in their invocation list. The <code>MulticastDelegate</code> class inherits from <code>Delegate</code>. Since you can't inherit from a value type, <code>Delegate</code> had to be a reference type.</p> <p>In the end, all actual delegates ended up being multicast delegates, but at that stage in the process, it was too late to merge the two classes. See this <a href="http://blogs.msdn.com/b/brada/archive/2004/02/05/68415.aspx" rel="noreferrer">blog post</a> about this exact topic:</p> <blockquote> <p>We abandoned the distinction between Delegate and MulticastDelegate towards the end of V1. At that time, it would have been a <strong>massive</strong> change to merge the two classes so we didn’t do so. You should pretend that they are merged and that only MulticastDelegate exists.</p> </blockquote> <p>In addition, delegates currently have 4-6 fields, all pointers. 16 bytes is usually considered the upper bound where saving memory still wins out over extra copying. A 64-bit <code>MulticastDelegate</code> takes up 48 bytes. Given this, and the fact that they were using inheritance suggests that a class was the natural choice.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload