接口函数C#

Ita*_*y.B 2 c# interface function

我有一个实现接口的功能.这样的事情:

string IMyInterface.MyFunction()
{
   do something;
}
Run Code Online (Sandbox Code Playgroud)

这个功能在我班级之外可用.一切都很完美.现在我还需要从另一个LOCAL非公共函数调用此函数.像这样:

void Func2()
{
  string s;
  s = MyFunction();
}
Run Code Online (Sandbox Code Playgroud)

问题是我得到这个错误:"MyFunction名称在当前上下文本地不存在"

任何帮助将不胜感激.

TY.

Wil*_*mpt 7

您已明确实现了接口方法.将"this"投射到界面,你就在那里:

void Func2()
{
    string s = ((IMyInterface)this).MyFunction();  
}
Run Code Online (Sandbox Code Playgroud)

  • 或者隐式实现该功能. (5认同)