out parameters and contravariance

M

Marcel Müller

Why does
public delegate void ActionOut<out T>(out T arg1);
not work?

From my understanding arg1 is only passed from the callee to the
caller, so it should be safe, if the delegate is invoked with a base
class of T.


Marcel
 
B

bradbury9

El martes, 16 de abril de 2013 14:04:17 UTC+2, Marcel Müller escribió:
Why does

public delegate void ActionOut<out T>(out T arg1);

not work?



From my understanding arg1 is only passed from the callee to the

caller, so it should be safe, if the delegate is invoked with a base

class of T.





Marcel

Maybe a bit dumb question but... It looks like 'too generic to work'. Should not the T derive from EventArg?

Something like:

public delegate void ActionOut<T>(T arg1) where T : EventArgs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top