The article states the following: http://msdn.microsoft.com/en-us/library/dd799517.aspx
Variance does not apply to delegate combination. That is, given two delegates of types Action<Derived>
and Action<Base>
(Action(Of Derived)
and Action(Of Base)
in Visual Basic), you cannot combine the second delegate with the first although the result would be type safe. Variance allows the second delegate to be assigned to a variable of type Action<Derived>
, but delegates can combine only if their types match exactly.
Action<B> baction = (taret) => { Console.WriteLine(taret.GetType().Name); };
Action<D> daction = baction;
Action<D> caction = baction + daction;
In the above code baction
and daction
take different parameters. But still I am able to combine them.
What am I missing?
TIA.