Can I have a type that's both, covariant and contravariant, i.e. fully fungible/changeable with sub

Posted by Water Cooler v2 on Stack Overflow See other posts from Stack Overflow or by Water Cooler v2
Published on 2010-05-11T10:40:33Z Indexed on 2010/05/11 10:44 UTC
Read the original article Hit count: 172

Just a stupid question. I could try it out in 2 minutes, really. It's just that I have 1 GB RAM and have already got 2 instances of VS 2010 open on my desktop, with an instance of VS 2005, too. Opening another instance of VS 2010 would be an over kill.

Can I have a type (for now forgetting its semantics) that can be covariant as well as contravariant?

For e.g.

public interface Foo<in out T>
{
    void DoFooWith(T arg);
}

Off to Eric Lippert's blog for the meat and potatoes of variance in C# 4.0 as there's little else anywhere that covers adequate ground on the subject.

© Stack Overflow or respective owner

Related posts about covariance

Related posts about c#4.0