c#界面问题

我有以下代码
// IMyInterface.cs

namespace InterfaceNamespace
{
    interface IMyInterface
    {
        void MethodToImplement();
    }
}

.

// InterfaceImplementer.cs
class InterfaceImplementer : IMyInterface
{
    void IMyInterface.MethodToImplement()
    {
        Console.WriteLine("MethodToImplement() called.");
    }
}

这段代码编译得很好(为什么?).但是,当我尝试使用它时:

// Main.cs

    static void Main()
    {
        InterfaceImplementer iImp = new InterfaceImplementer();
        iImp.MethodToImplement();
    }

我明白了:

06003

即从外部看不到MethodToImplement.但是,如果我做了以下更改:

// InterfaceImplementer.cs
class InterfaceImplementer : IMyInterface
{

    public void MethodToImplement()
    {
        Console.WriteLine("MethodToImplement() called.");
    }
}

然后Main.cs编译也很好.为什么这两者有区别?

解决方法

implementing an interface explicitly,您正在创建一个只能通过强制转换到接口来调用的私有方法.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...