我有一些類如下其中實現一個接口:定義類型的屬性「的Class1:接口1」到另一個接口
class C1 : IpropTemplate { ... }
class C2 : IpropTemplate { ... }
:
也有是實現另一個接口的一些其它類:
class C3 : IclassTemplate { ... }
現在,我需要在IclassTemplate
中指定一個屬性的簽名,以強制C3
擁有一個從IpropTemplate
實現的屬性。 (如C1
或C2
等)
我嘗試這樣做:
interface IclassTemplate
{
...
IpropTemplate prop1 { get; set; }
}
class C3 : IclassTemplate
{
...
public C1 prop1
{
get;
set;
}
}
在這種情況下,編譯器生成指示C3
不實現接口構件IclassTemplate.prop1
並且該C3.prop1
不能實現IpropTemplate.prop1
由於出錯它沒有匹配的返回類型IpropTemplate
。
我該怎麼辦? 感謝
感謝您關於把現場的界面提示。我沒有在我的編程中放入一個字段。但是在這裏我不小心編寫了代碼片段,我已經糾正了它。 – Mimi
@Mimi:好的,我會編輯。您可能想要讓您的示例名稱同時遵循.NET命名約定;) –