I have
public interface IFoo
{
IEnumerable<IThingy> Thingies{get;}
}
I want to then be able to do
class Thing1 : IThingy
{
...
}
class ImplementFoo : IFoo
{
List<Thing1> m_things;
IEnumerable<IThingy> Thingies {get {return m_things;}}
}
ImplementFoo.Thingies returns an IList (which is an IEnumerable) of Thing1s (which are IThings). So in theory this code should work, but it does not. VS suggests a cast in the getter; that compiles but fails at run time. Am I expecting too much of covariance in c# 4?
VS 2010 -> Silverlight 4. Here’s the compile error
Cannot implicitly convert type ‘
System.Collections.Generic.List<MyProj.Column>‘ to ‘System.Collections.Generic.IEnumerable<MyProj.IColumn>‘. An explicit conversion exists (are you missing a cast?)
EDIT: People tell me this should work, but it doesnt work in SL4
THis is a difference between SL4 and CLR4. THe IEnumerable interface is not marked ‘out’. Apparently fixed in SL5