C# 没有实现接口成员错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12649632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does not implement interface member Error
提问by cdietschrun
Here's my code, VS2012 C# Express is complaining about the non implementation of the two members in the interface PISDK._DEventPipeEvents, which is pasted here quickly:
下面是我的代码,VS2012 C# Express 抱怨接口PISDK._DEventPipeEvents 中的两个成员没有实现,赶紧贴在这里:
namespace PISDK
{
[Guid("9E679FD2-DE8C-11D3-853F-00C04F45D1DA")]
[InterfaceType(2)]
[TypeLibType(4096)]
public interface _DEventPipeEvents
{
[DispId(2)]
void OnNewValue();
[DispId(1)]
void OnOverflow(object vtEvent, OverflowCauseConstants Cause);
}
}
and here's my code:
这是我的代码:
class PointListEventPipeEventReceiver : PISDK._DEventPipeEvents
{
private PISDK.EventPipe eventPipe;
public PointListEventPipeEventReceiver(PISDK.EventPipe eventPipe)
{
this.eventPipe = eventPipe;
}
public void PISDK._DEventPipeEvents.OnNewValue()
{
Console.WriteLine("New value event");
handleNewValue(eventPipe);
}
public void PISDK._DEventPipeEvents.OnOverFlow(object vtEvent, PISDK.OverflowCauseConstants Cause)
{
throw new NotImplementedException();
}
private void handleNewValue(PISDK.EventPipe eventPipe)
{
Console.WriteLine("Handling new value");
Array eventObjs = eventPipe.TakeAll();
Console.WriteLine("eventObjs.Length==" + eventObjs.Length);
foreach (PISDK.PIEventObject piEventObj in eventObjs)
{
Console.WriteLine(piEventObj.EventData as PISDK.PointValue);
}
}
}
I'm at a loss here, any help is nice.
我在这里不知所措,任何帮助都很好。
采纳答案by phoog
In addition to getting the case wrong in "overflow", it looks like you're trying to apply the publicaccess modifier to an explicit interface member implementation. You can either implement the member implicitly as a public member, or explicitly, but not both.
除了在“溢出”中出错之外,您似乎还试图将public访问修饰符应用于显式接口成员实现。您可以将成员隐式实现为公共成员,也可以显式实现,但不能同时实现。
Implicit implementation:
隐式实现:
public void OnOverflow(object vtEvent, PISDK.OverflowCauseConstants Cause)
{
throw new NotImplementedException();
}
Explicit implementation:
显式实现:
void PISDK._DEventPipeEvents.OnOverflow(object vtEvent, PISDK.OverflowCauseConstants Cause)
{
throw new NotImplementedException();
}
回答by dasblinkenlight
Your implementation uses OnOverFlowwith a capital Finstead of a lowercase one in the interface. The method should be called OnOverflow.
您的实现在接口中使用OnOverFlow大写F而不是小写。应该调用该方法OnOverflow。

