我試圖圍繞接口包裹頭部。我一直在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