Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未实现接口成员错误_C#_Api_Interface_Implementation - Fatal编程技术网

C# 未实现接口成员错误

C# 未实现接口成员错误,c#,api,interface,implementation,C#,Api,Interface,Implementation,以下是我的代码,VS2012 C#Express正在抱怨接口PISDK中的两个成员未实现。DEventPipeEvents会很快粘贴到这里: namespace PISDK { [Guid("9E679FD2-DE8C-11D3-853F-00C04F45D1DA")] [InterfaceType(2)] [TypeLibType(4096)] public interface _DEventPipeEvents { [DispI

以下是我的代码,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);
    }
}
这是我的代码:

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);
        }
    }
}

我在这里不知所措,任何帮助都很好

您的实现使用
OnOverFlow
,在接口中使用大写的
F
,而不是小写的。该方法应该被称为
OnOverflow

除了在“overflow”中的大小写错误之外,它看起来像是在尝试将
public
access修饰符应用于显式接口成员实现。可以将该成员隐式实现为公共成员,也可以显式实现,但不能同时实现两者

隐式实现:

public void OnOverflow(object vtEvent, PISDK.OverflowCauseConstants Cause) 
{ 
    throw new NotImplementedException(); 
} 
void PISDK._DEventPipeEvents.OnOverflow(object vtEvent, PISDK.OverflowCauseConstants Cause) 
{ 
    throw new NotImplementedException(); 
} 
明确执行:

public void OnOverflow(object vtEvent, PISDK.OverflowCauseConstants Cause) 
{ 
    throw new NotImplementedException(); 
} 
void PISDK._DEventPipeEvents.OnOverflow(object vtEvent, PISDK.OverflowCauseConstants Cause) 
{ 
    throw new NotImplementedException(); 
} 

如果你是C#新手,你需要记住它是区分大小写的。@Tim:或者右键单击界面
Foo:IFoo
,然后选择
implementation the interface
,这保证了正确的拼写。@DannyChen-是的。我完全忘记了那个选项。这更是我不知道的问题,因为我是C#的新手。非常感谢。@cdietschrun不客气。当我刚接触C#时,我花了一些时间来理解这个概念,但现在我明白了,我一直在使用它。这是一种功能强大且被低估的技术。