[英]Not implementing interface member - C#
I keep getting this error, and I am unsure what I am doing wrong. 我不断收到此错误,并且不确定自己在做什么错。 Error 1 'Home.Services.InventoryImpl' does not implement interface member 'Home.Services.InventorySvc.CreateInventory(Home.Services.InventoryImpl)'
错误1'Home.Services.InventoryImpl'未实现接口成员'Home.Services.InventorySvc.CreateInventory(Home.Services.InventoryImpl)'
My Interface Code 我的界面代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Home;
using Home.Domain;
namespace Home.Services
{
public interface InventorySvc
{
void CreateInventory(InventoryImpl CreateTheInventory);
}
}
My Implementation Code 我的实施代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Home.Domain;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace Home.Services
{
public class InventoryImpl: InventorySvc
{
public void CreateTheInventory(CreateInventory createinventory)
{
FileStream fileStream = new FileStream
("CreateInventory.bin", FileMode.Create,
FileAccess.Write);
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, createinventory);
fileStream.Close();
}
}
}
Your method is called CreateTheInventory
but in the interface it is called CreateInventory
. 您的方法称为
CreateTheInventory
但在界面中称为CreateInventory
。 The method signature must exactly match the interface member in order for the compiler to treat that method as implementing the interface member, and the names do not match. 方法签名必须与接口成员完全匹配,以便编译器将该方法视为实现接口成员,并且名称不匹配。
Further, the argument types do not match -- in your implementation you have CreateInventory
as the argument type, but the interface takes an argument of type InventoryImpl
. 此外,参数类型不匹配-在您的实现中,您将
CreateInventory
作为参数类型,但是接口采用了InventoryImpl
类型的参数。
If you correct these two errors, your code should build. 如果您纠正了这两个错误,则应该构建代码。
Your InventorySvc
interface defines: 您的
InventorySvc
界面定义:
void CreateInventory(InventoryImpl CreateTheInventory);
But you have implemented: 但是您已经实现了:
public void CreateTheInventory(CreateInventory createinventory)
See the difference? 看到不同?
Your method signature in the class does not match the interface method's signature. 您在类中的方法签名与接口方法的签名不匹配。
Use the smart tag that appears when hovering with the mouse over the interface name, in order to create the interface implementation. 使用将鼠标悬停在接口名称上时出现的智能标记,以创建接口实现。 This makes everything right for you.
这使一切都适合您。
Also, you should call your interface IInventorySvc
. 另外,您应该调用接口
IInventorySvc
。 The guidelines for interface names state that an uppercase "I" should be placed before the logical name, even if the latter one starts with an "I". 接口名称的准则指出,即使逻辑名称以“ I”开头,也应在逻辑名称之前放置一个大写的“ I”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.