实现接口我有以下问题:与列表<T>财产
public interface IControlSingleContainer
{
ControlCollection Content { get; set; }
}
public interface IControlCollectionContainer
{
// I need to obtain a List of objects that implement IControlSingleContainer interface
List<IControlSingleContainer> Items { get; set; }
}
public class TabItem : IControlSingleContainer
{
public ControlCollection Content { get; set; }
}
public class TabbedContainer : IControlCollectionContainer
{
public List<TabItem> Items { get; set; } <- ERROR!
}
这段代码期望List<IControlSingleContainer>
在房地产TabbedContainer.Items
但我尽量用包含实现IControlSingleContainer
对象Items
属性创建类。
编辑:基本上,编译错误如下: 'Cosmo.UI.Controls.TabbedContainer' does not implement interface member 'Cosmo.UI.Controls.IControlCollectionContainer.Items'. 'Cosmo.UI.Controls.TabbedContainer.Items' can not implement' Cosmo.UI.Controls.IControlCollectionContainer.Items' because it has the kind of matching return value of 'System.Collections.Generic.List <Cosmo.UI.Controls. IControlSingleContainer>'
。
我探索与通用接口,但没有任何结果的解决方案...
如果你遇到一个错误,并且你发布了这个问题寻找帮助修复这个错误....但是甚至没有打扰说错误实际上是什么,那么你失败了。 – 2015-02-23 23:54:09
有什么错误消息?我打赌这是一个对象引用错误,因为你没有实例化列表。尝试在类的构造函数中实例化列表 – 2015-02-23 23:55:36
嗨JK,我的英语不是最好的......对不起!我试着更好地解释这个错误:当你编译代码时,我在TabbedContainer类的Items属性中得到一个错误,因为它期望列表List。我真的希望这个列表适用于实现接口IControlSingleContainer的类。我无法找到如何得到这个。我希望这是清楚我的问题...... :) –
2015-02-24 00:02:22