C# .NET类接口、继承和库:错误未实现接口成员

C# .NET类接口、继承和库:错误未实现接口成员,c#,.net,wpf,winforms,silverlight,C#,.net,Wpf,Winforms,Silverlight,我想这样做(我在silverlight上,但没有什么特别的,所以我也想在winform和wpf上这样做) 但是你会得到这个错误 错误2“MyComponents.IMymanager”未实现接口成员“lib.manager.ILibManager.SetModel(lib.model.ILibModel)”MyComponents.IMymanager.SetModel(lib.model.ILibModel)“”无法实现接口成员,因为它不是公共的。C:…\MyComponents\MyComp

我想这样做(我在silverlight上,但没有什么特别的,所以我也想在winform和wpf上这样做)

但是你会得到这个错误

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

为什么??这是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
    {

    }
}
请尝试以下方法:

namespace MyComponents
{
    public class MyManager : ILibManager
    {
        public void SetModel(ILibModel model)
        {
           // ...
        }
    }
}
符合接口(契约!)的类必须以公共方式实现它。

尝试以下方法:

namespace MyComponents
{
    public class MyManager : ILibManager
    {
        public void SetModel(ILibModel model)
        {
           // ...
        }
    }
}

符合接口(契约!)的类必须以公开的方式实现它。

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

因此,我认为应该为该方法创建一个主体,然后它必须是“公共的”,因为它是接口实现的一部分。您还应该将IMyManager重命名为“MyManager”,因为它不是一个接口。你应该这样上课:

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

希望这有帮助:)

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

因此,我认为应该为该方法创建一个主体,然后它必须是“公共的”,因为它是接口实现的一部分。您还应该将IMyManager重命名为“MyManager”,因为它不是一个接口。你应该这样上课:

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

希望这有帮助:)

您也可以尝试显式实现,例如:

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

您还可以尝试显式实现,例如:

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

好吧,我犯了一个错误,但不是全部。我还在接口中声明了public void。好吧,我在那个里犯了一个错误,但并不是全部。我还在接口中声明了publicsvoid。