为什么接口的显式实现不能公开? [英] Why Explicit Implementation of a Interface can not be public?

查看:140
本文介绍了为什么接口的显式实现不能公开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类的方法是实现接口。当我把它明确执行我的编译器错误

I have method in Class which is implementation of Interface. When I made it Explicit implementation I got compiler error

The modifier 'public' is not valid for this item

为什么不允许有公共显式接口实现?

推荐答案

之所以显式接口实现,以避免最终结果是该对象必须明确地映射到该接口调用这些方法之前,名称冲突。

The reason for an explicit interface implementation is to avoid name collisions with the end result being that the object must be explicitly cast to that interface before calling those methods.

您可以把这些方法不是公职的类,但被直接连接到该接口。没有任何理由指定公共/私营/保护,因为它永远是公众的接口不能有非公共成员。

You can think of these methods not as being public on the class, but being tied directly to the interface. There is no reason to specify public/private/protected since it will always be public as interfaces cannot have non-public members.

(微软对显式接口实现的概述)

(Microsoft has an overview on explicit interface implementation)

这篇关于为什么接口的显式实现不能公开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆