Compilation Error: “The modifier 'public' is not valid for this item” while explicitly implementing the interface

后端 未结 5 1532
遥遥无期
遥遥无期 2020-12-02 16:33

I am getting this error while creating a public method on a class for explicitly implementing the interface. I have a workaround: by removing the e

5条回答
  •  孤城傲影
    2020-12-02 16:57

    This is an Explicit implementation, the default scope for the members of the interface is public, whereas it is private in case of a class, ergo, there is no need to use the Public modifier because when we call that method it would be called with the reference of the interface only.

    According to "MSDN Explicit Interface Implementation" the functions that implement explicit interfaces are never explicitly defined public. They are public by default. It would be meaningless to define them otherwise.

提交回复
热议问题