我试图围绕接口包裹头部。我一直在imp on这样的事情:将接口集合添加到接口
public interface IFoo
{
ICollection<IBar> Bars { get; set; }
//some other properties
}
public interface IBar
{
//some properties
}
//assume Bar is implemented and extends IBar. Some instaces of Bar are created
Bar[] MyBars = {bar1, bar2};
Foo MyFoo = new Foo();
MyFoo.Bars=MyBars.ToList(); //This causes an error saying Collection<Bar> cannot be
//assigned to ICollection<IBar>.
我完全在如何正确地做到这一点的损失。填充接口集合的正确方法是什么?
编辑:我实施Foo的方式可能是问题的一部分。
public class Foo : IFoo
{
public ICollection<IBar> Bars { get; set; }
}
您是否试过使用Collection而不是ICollection ? –
你可以发布Foo类吗? –
@Fuex foo类可能是问题的一部分。一会儿。 – Billdr