UPDATE: The following code only makes sense in C#4.0 (Visual Studio 2010)
It seems like I am having some misunderstanding of covariance/contravariance thing. Can anybody tell me why the following code doesn't compile?
public class TestOne<TBase>
{
public IEnumerable<TBase> Method<TDerived>(IEnumerable<TDerived> values)
where TDerived: TBase
{
return values;
}
}
while this one compiles: (!!!)
public interface IBase
{
}
public interface IDerived: IBase
{
}
public class TestTwo
{
public IEnumerable<IBase> Method(IEnumerable<IDerived> values)
{
return values;
}
}