In .NET 1.1 a delegate defined like
delegate void Proc(string foo);
Could only be instantiated with a method which had that exact signature. In .NET 2.0 they relaxed it so that a method defined as
void MyProc( object bar );
Could be wrapped by the above delegate, since MyProc parameter is more restrictive, which makes sense.However what you can't do is
delegate void Proc(int foo);
And make it wrap up
void MyProc(object bar );
The compiler will not let you...Hold on, int ultimately derives from System.Object so why not. My guess is that it comes down to boxing, since in order to make code work the method MyProc must see a reference type. The code invoking the delegate, or the CLR generated code would have to be smart enough to see that the actual implementation was expecting a reference type and perform a boxing operation on the parameters being passed. So perhaps the seamless type system is starting to show a few cracks....
1 comment:
Hey just stopping by to say I like the blog.
I don't know if your also into Jujitsu but I got sites and Squidoo lenses on Jujitsu if your intested:
Jujitsu
Jujitsu For Women
Japanese Jujitsu
Jujitsu Philosophy
Hope you like them and I will come by again!
Post a Comment