2011-04-20 83 views
0

我想这样做(我对Silverlight的,但没有具体的所以要做到这一点也WinForm的和WPF).NET类接口,继承和图书馆:误差不实现接口成员

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

为什么?这是库

代码
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 
    { 

    } 
} 

回答

2

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

所以,我相信你应该有一个方法的机构,然后它必须是“公开”的,因为它是接口实现的一部分。而且您还应该将IMyManager重命名为“MyManager”,因为它不是接口。你应该有你的类是这样的:

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

希望这有助于:)

+0

好,我犯了一个错误有但那一点都不高。我也在界面中声明了public void。 – user310291 2011-04-20 16:10:49

1

试试这个:(!合同)

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

符合接口的类必须在公开的方式实现它。

1

您也可以尝试明确的实现,如:

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