公共私人保护 [英] Public Private Protected

查看:69
本文介绍了公共私人保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

充分说明公共私人和保护....为什么可以使用.....

并举一些示例程序







谢谢

解决方案

从这里开始尝试访问修饰符(C#参考) [ ^ ]。


好吧,在提到一些东西之前,我可以说你对这些术语的看法。

从字面上看,这些术语称为访问修饰符。当您声明公开时,该类(以及对象)正在强烈声明:这是我的可见界面,还有很多其他像这样,但这是我的。公共接口是一个合同协议,您的类正在向世界其他地方(无论这意味着)输出它可以做什么。如果你修改公共界面,你就有可能违反世界其他地方对该课程的承诺。



另一方面,私人东西是课堂内部的东西。这是类必须使用的支持功能,以便执行其工作,同时携带对象状态(如果它是方法)或保持其内部状态(如果它是变量)。您可以随意破解和修改类私有内容,而不会破坏接口契约,这意味着这为您提供了很大的重构自由(内部数据表示,例如,效率)。私有东西不是界面的一部分。



受保护的涉及重新实现的开放性。如果可以的话,尽量避免深层嵌套的遗产。你冒着让事情变得非常困难的风险,因为基类可以被你的重新实现课搞砸了。



在这背后,检查CP的一些非常好的答案我想在这里参考:

c#中的访问修饰符 ^ ]



并且,您还可以从中查看辅助功能级别:

可访问性级别 [ ^ ]

give full explanation of public private and protect....why it can be used.....
and give some example program



thanks

解决方案

Try starting here Access Modifiers (C# Reference)[^].


Well,before referring something i can say you about my thoughts about those terms.
Literally these terms are called Access Modifiers.When you declare something public, the class (and consequently the object) is making a strong statement: this is my visible interface, there are many other like this but this is mine. The public interface is a contractual agreement that your class is exporting to the rest of the world (whatever that means) about what it can do. If you modify the public interface, you risk to break the contract that the rest of the world is assuming about the class.

On the other hand, private stuff is internal to the class. It is support functionality that the class must use in order to do its job, while carrying the object state around (if it's a method) or keeping its internal state (if it's a variable). You are free to hack and tinker the class private stuff as much as you want, without breaking the interface contract, meaning that this gives you wide freedom for refactoring (of the internal data representation, for example, for efficiency). private stuff is not part of the interface.

Protected is something that involves the openness to reimplementation. Avoid, if you can, deeply nested inheritances. You risk to make things very difficult to handle, as the base class can be screwed by your reimplementation class.

Behind this,check some really good answers from CP that i like to refer here:
access modifiers in c#[^]

And,you can check also Accessibility Levels from it:
Accessibility Levels[^]


这篇关于公共私人保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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