Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT 2</strong> I don't believe this answer anymore, but I left it here so the thread would still make sense and so that people would see why it isn't right. See my other answer for a different take on the matter.</p> <p><strong>Original</strong></p> <p>Because it would require implicitly boxing the value type receiver parameter (because the _target field in the System.Delegate type which holds the the receiver parameter is of type System.Object), which could lead to some strange aliasing behavior if you weren't expecting it.</p> <p><strong>EDIT</strong></p> <p>There is something else going on here. I ran this sample program:</p> <pre><code>class Program { public static int Combine(int a, int b) { return a + b; } static void Main(string[] args) { var combineMethod = typeof(Program).GetMethod("Combine"); var add4 = Delegate.CreateDelegate( typeof(Converter&lt;int, int&gt;), 4, combineMethod) as Converter&lt;int, int&gt;; for (int i = 0; i &lt; 10; i++) { Console.WriteLine(add4(i)); } Console.ReadLine(); } } </code></pre> <p>and got an ArgumentException: "Error binding to target method." at the call to CreateDelegate. I'm not sure why, and because the relevant method is an <code>internalcall</code> method, Reflector isn't much help. The <a href="http://msdn.microsoft.com/en-us/library/74x8f551.aspx" rel="nofollow noreferrer">documentation for CreateDelegate</a> also wasn't much help. I'm sure it has something to do with boxing the receiver, maybe someone with knowledge of the Rotor source could help explain why?</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