static void FunWithCovariance() { IFoo <Base> ifbase = new Foo <Base>(); IFoo <Sub> ifsub = new Foo <Sub>(); Base b = new Sub(); IFoo <Sub> ifbase2 = new Foo <Base>(); DoSomethingWithBase(new Base()); DoSomethingWithBase(new Sub()); //DoSomethingWithSub(new Base()); DoSomethingWithSub(new Sub()); Base b2 = MethodThatReturnsBase(); //Sub s2 = MethodThatReturnsBase(); IEnumerable <Base> ib = new List <Sub>(); Base b3; b3 = MethodWithOut(); }
public static void DoSomethingWithSub(Sub b) { }