访问修饰符是什么意思 [英] what is meant by access modifiers

查看:211
本文介绍了访问修饰符是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问修饰符是什么意思?

what is meant by access modifiers?

推荐答案

访问修饰符是对变量或任何其他对象的访问级别.
例如:public emp emp emp = null;

这表示即使在装配体之外也可以访问员工,有四个访问修饰符:

民众. -全球
私人-本地上课
受保护-本地以及派生类
内部-在Assembly中
Acces modifiers, are the level of access given to a variable or any other objects.

Ex: public Employee emp = null;

This says the employee is accessible throughout, even outside the assembly, there are four access modifiers:

Public. - Global
Private - Local to class
Protected - Local and also to derived classes
internal - Within Assembly


使用封装时,必须始终考虑类型的哪些方面是可见的
到应用程序的各个部分.具体来说,类型(类,接口,结构,枚举和
委托及其成员(属性,方法,构造函数和字段)是使用
定义的 用于控制项目对应用程序其他部分的可见性"的特定关键字.尽管C#
定义了许多关键字来控制访问,它们在成功应用的地方有所不同
(类型或成员).

这是每个访问修饰符的作用.

公开:公共物品无法访问
限制.公开成员可以是
从对象以及
访问 任何派生类.公共类型可以
可从其他外部访问
装配体.

私人:只能访问私人物品
根据该类(或结构)
定义项目.

保护:受保护的物品可以由
使用 定义它的类,以及任何子类
班级.但是,受保护的物品
无法从外部访问
使用C#点运算符的世界.

内部:内部项目仅可访问
在当前程序集中.
因此,如果您定义一组
.NET类中的内部类型
库,其他程序集不可用
利用它们.

受保护的内部:当受保护且内部
关键字组合在一个项目上,
该项目可在
内访问 定义程序集,定义
类和派生类.

------------------------------------------

希望这对您有帮助..祝一切顺利!!
When working with encapsulation, you must always take into account which aspects of a type are visible
to various parts of your application. Specifically, types (classes, interfaces, structures, enumerations, and
delegates) as well as their members (properties, methods, constructors, and fields) are defined using a
specific keyword to control how ''visible'' the item is to other parts of your application. Although C#
defines numerous keywords to control access, they differ on where they can be successfully applied
(type or member).

Here is role of each of the access modifiers.

public:Public items have no access
restrictions. A public member can be
accessed from an object as well as
any derived class. A public type can
be accessed from other external
assemblies.

private:Private items can only be accessed
by the class (or structure) that
defines the item.

protected:Protected items can be used by the
class which defines it, and any child
class. However, protected items
cannot be accessed from the outside
world using the C# dot operator.

internal:Internal items are accessible only
within the current assembly.
Therefore, if you define a set of
internal types within a .NET class
library, other assemblies are not able
to make use of them.

protected internal:When the protected and internal
keywords are combined on an item,
the item is accessible within the
defining assembly, the defining
class, and by derived classes.

------------------------------------------

Hope this will help you.. All the very best.!!


这篇关于访问修饰符是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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