Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未实现接口成员-C_C# - Fatal编程技术网

C# 未实现接口成员-C

C# 未实现接口成员-C,c#,C#,我不断地犯这个错误,我不确定我做错了什么。错误1“Home.Services.InventoryImpl”未实现接口成员“Home.Services.InventorySvc.CreateInventoryHome.Services.InventoryImpl” 我的接口代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Home; using Home.Do

我不断地犯这个错误,我不确定我做错了什么。错误1“Home.Services.InventoryImpl”未实现接口成员“Home.Services.InventorySvc.CreateInventoryHome.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();
        }
    }
}
您的方法称为CreateTheInventory,但在接口中称为CreateInventory。方法签名必须与接口成员完全匹配,以便编译器将该方法视为实现接口成员,并且名称不匹配

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

如果您更正了这两个错误,则应生成代码。

您的InventorySvc接口定义:

void CreateInventory(InventoryImpl CreateTheInventory);
但你已经实施了:

public void CreateTheInventory(CreateInventory createinventory)

看到区别了吗?

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

使用鼠标悬停在接口名称上时显示的智能标记来创建接口实现。这让一切都适合你


另外,您应该调用接口IInventorySvc。接口名称指南规定,即使逻辑名称以I开头,也应在逻辑名称前加上大写的I。

此处同意,要加上我的2美分,在键入:InventorySvc后,右键单击接口并选择ImplementInterface,这将创建作为nessisary的方法和属性,然后您只需填写实际代码。