0

我不断收到这个错误,我不确定我做错了什么。错误 1“Home.Services.InventoryImpl”未实现接口成员“Home.Services.InventorySvc.CreateInventory(Home.Services.InventoryImpl)”

我的界面代码

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);
    }
}

我的实现代码

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();
        }
    }
}
4

3 回答 3

9

您的方法被调用CreateTheInventory,但在接口中被调用CreateInventory。方法签名必须与接口成员完全匹配,以便编译器将该方法视为实现接口成员,并且名称不匹配。

此外,参数类型不匹配 - 在您的实现中,您CreateInventory将参数类型作为参数类型,但接口采用 type 的参数InventoryImpl

如果您更正了这两个错误,您的代码应该会构建。

于 2012-09-28T18:16:58.900 回答
2

您的InventorySvc界面定义:

void CreateInventory(InventoryImpl CreateTheInventory);

但是你已经实现了:

public void CreateTheInventory(CreateInventory createinventory)

看到不同?

于 2012-09-28T18:17:55.173 回答
0

您在类中的方法签名与接口方法的签名不匹配。

使用将鼠标悬停在接口名称上时出现的智能标记,以创建接口实现。这使一切都适合您。

此外,您应该调用您的 interface IInventorySvc。接口名称的指导方针规定大写的“I”应该放在逻辑名称之前,即使后者以“I”开头。

于 2012-09-28T18:39:21.130 回答