如何在c#中保护接口实现? [英] How to make interface implementation protected in c#?

查看:102
本文介绍了如何在c#中保护接口实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现接口后,所有方法都将在实现的类中公开。如何减少已实现方法的范围?

解决方案

默认情况下,接口成员是公共的。



如何实现接口而不使成员公开使用显式接口实现 [ ^ ]是一种使用显式接口实现的解决方法。


接口就是 - 接口。公共合同,没有别的。把界面想象成规范,描述实现应该如何看待外部世界。如果你想要保护去抽象基类

希望这有帮助

Once an Interface is implemented all methods will be public in implemented class . How to reduce the scope of the implemented method?

解决方案

Interface members are public by default.

How to Implement an Interface Without Making Members Public Using Explicit Interface Implementation[^] is a workaround that uses explicit interface implementation.


Interfaces are just that - interfaces. A public contract, nothing else. Think of interface as of specification which describes how should the implementation look to the outside world.If you want to make protected go for abstract base classes
Hope this helps


这篇关于如何在c#中保护接口实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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