Is C# 4.0 Tuple covariant

Posted by RichK on Stack Overflow See other posts from Stack Overflow or by RichK
Published on 2010-05-20T10:28:20Z Indexed on 2010/05/20 10:30 UTC
Read the original article Hit count: 287

Filed under:
|
|

(I would check this out for myself, but I don't have VS2010 (yet))

Say I have 2 base interfaces:

IBaseModelInterface
IBaseViewInterface

And 2 interfaces realizing those:

ISubModelInterface : IBaseModelInterface
ISubViewInterface : IBaseViewInterface

If I define a Tuple<IBaseModelInterface, IBaseViewInterface> I would like to set that based on the result of a factory that returns Tuple<ISubModelInterface, ISubViewInterface>.

In C# 3 I can't do this even though the sub interfaces realize the base interfaces. And I'm pretty sure C# 4 lets me do this if I was using IEnumerable<IBaseModelInterface> because it's now defined with the in keyword to allow covariance. So does Tuple allow me to do this?

From what (little) I understand, covariance is only allowed on interfaces, so does that mean there needs to be an ITuple<T1, T2> interface? Does this exist?

© Stack Overflow or respective owner

Related posts about c#

Related posts about covariance