.NET类接口,继承和库:错误未实现接口成员 [英] .NET Class Interface, Inheritance and Library: error does not implement interface member

查看:42
本文介绍了.NET类接口,继承和库:错误未实现接口成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做(我正在使用Silverlight,但没有具体说明,所以也想在winform和wpf上这样做)

I want to do this (I'm on silverlight but nothing specific so want to do this also on winform and wpf)

namespace MyComponents
{
    public class IMyManager : ILibManager
    {
        void SetModel(ILibModel model);
    }
}

但出现此错误

错误2'MyComponents.IMymanager'未实现接口成员'lib.manager.ILibManager.SetModel(lib.model.ILibModel)'.'MyComponents.IMymanager.SetModel(lib.model.ILibModel)'无法实现接口成员,因为它不是公共的.C:... \ MyComponents \ MyComponents \ IMymanager.cs 17 18 MyComponents

Error 2 'MyComponents.IMymanager' does not implement interface member 'lib.manager.ILibManager.SetModel(lib.model.ILibModel)'. 'MyComponents.IMymanager.SetModel(lib.model.ILibModel)' cannot implement an interface member because it is not public. C:...\MyComponents\MyComponents\IMymanager.cs 17 18 MyComponents

为什么?这是Lib中的代码

Why ? This is the code in Lib

using lib.model;

using System;
using System.Collections.Generic;
using System.Text;

namespace lib.manager
{
    public interface ILibManager
    {
        public void SetModel(ILibModel model);
    }
}

using lib.model;

using System;
using System.Net;
using System.Windows;


namespace lib.manager
{
    public class Manager: IManager
    {
        // Constructor
        public Manager() { 

        }

        public void SetModel(ILibModel model) {

        }

    }
}

namespace lib.model
{
    public interface ILibModel
    {

    }
}


namespace lib.model
{
    public class Model : ILibModel
    {

    }
}

推荐答案

我相信您在这里有两个错误,不是吗?应该有一个错误,说SetModel应该有一个主体,因为IMyManager不是接口或抽象类!

I believe you had two errors here, didn't you? there should be an error saying that SetModel should have a body because IMyManager isn't an interface or an abstract class!

因此,我认为您应该为该方法提供一个主体,然后它必须是公共的",因为它是接口实现的一部分.并且您还应该将IMyManager重命名为"MyManager",因为它不是接口.您应该像这样上课:

So, I believe you should have a body for that method, and then it has to be "public" since it's part of an implementation of an interface. And you should also rename IMyManager to be "MyManager", since it's not an interface. you should have your class like this:

public class MyManager : ILibManager
{
    public void SetModel(ILibModel model)
    {
        // implementation of SetModel
    }
}

希望这会有所帮助:)

这篇关于.NET类接口,继承和库:错误未实现接口成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆