實現接口我有以下問題:與列表<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