我收到编译错误:错误CS0535 'COITemplateWriter‘没有为以下代码实现接口成员'iTemplateWriter.Write(iTemplateModel)’TemplateService:
public COITemplate Write(COITemplateModel model)
{
throw new NotImplementedException();
}上述方法的接口签名如下:
public interface iTemplateWriter
{
public iTemplate Write(iTemplateModel model);
}类型COITemplate实现iTemplate接口,类型COITemplateModel实现iTemplateModel接口,那么为什么这段代码会失败呢?如果接口需要方法返回实现iTemplate的任何内容并将实现iTemplateModel的任何内容作为参数进行编译,这不是很合理吗?
发布于 2021-05-21 05:09:50
如果没有看到COITemplate的其余部分,假设它不是一个接口,那么您应该只需要让函数返回接口类型本身。
public iTemplateWriter Write(COITemplateModel model)
{
// if the "COITemplateModel" class is an iTemplateWriter you could just return that back.
return model;
// OR if some other object you are working with is that interface.
return (iTemplateWrite)OfWhateverClassYouAreTrying;
}https://stackoverflow.com/questions/67627878
复制相似问题