【发布时间】:2017-12-28 08:40:17
【问题描述】:
编辑:已解决。我有时是个白痴。请参阅下面的自我回答...
我正在使用接口和多态性处理以下 C# .Net4.5 代码
public interface IFile
{
List<string> Contents {get;set;}
}
public class File : IFile
{
public List<string> Contents {get;set;}
}
public interface ICommandFile : IFile
{
new List<ICommandFileLine> Contents {get;set;} /*ICommandFileLine is defined in the code as well, but I don't believe this is pertinent to the issue I am having.*/
}
public class CommandFile : File, ICommandFile
{
public new List<ICommandFileLine> Contents {get;set;}
}
当我尝试执行上述操作时,预编译器会抱怨:
CommandFile 没有实现接口成员 “ICommandFile.Contents”。 'File.Contents' 无法实现 “ICommandFile.Contents”,因为它没有匹配的返回 “列表[ICommandFileLine]”的类型
接口成员“List ICommandFile.Contents”不是 实施。
我不明白。我用的是new关键字,这应该说明我想封装基类并定义新的变量类型吧?
【问题讨论】:
标签: c# inheritance interface polymorphism encapsulation