Is is possible to make the following compile without:
- Making
IFooCollection
generic - Explicitly implementing
IFooCollection.Items
onFooCollection
and performing an explicit cast.
public interface IFoo
{
}
public interface IFooCollection
{
IEnumerable<IFoo> Items { get; }
}
public class FooCollection<T> : IFooCollection where T : IFoo
{
public IEnumerable<T> Items { get; set; }
}
I'm happy enough with the second solution (implementing the interface explicitly) but would like to understand why I need to cast T
as IFoo
when we have a generic constraint specifying that T
must implement IFoo
.