点网中的访问修饰符 [英] access modifier in the dot net

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

问题描述

点网中使用的访问修饰符的级别是什么?

What are the level of the access modifier used in the dot net ?

推荐答案

访问修饰符不可分割的一部分面向对象程序设计.

它们支持encapsulation的概念,该概念促进了隐藏功能的思想.

访问修饰符允许您定义有权访问某些功能的人.

  • 公共
    -无访问限制
    -该类型或成员可以被同一程序集或引用该程序集的另一个程序集中的任何其他代码访问.
  • 受保护的
    -访问仅限于类定义以及从该类继承的任何类之内.
    -类型或成员只能由相同类或结构中的代码或从该类派生的类中的代码访问.
  • 内部
    -访问仅限于当前项目程序集中定义的类.
    -类型或成员只能由相同类或结构中的代码访问.
  • 私有
    -访问仅限于类定义内;如果没有正式指定,则这是默认的访问修饰符类型.
    -该类型或成员可以由同一程序集中的任何代码访问,但不能从另一个程序集中访问.
Access modifiers are an integral part of object-oriented programming.

They support the concept of encapsulation, which promotes the idea of hiding functionality.

Access modifiers allow you to define who does or doesn''t have access to certain features.

  • public
    -No restrictions to access
    -The type or member can be accessed by any other code in the same assembly or another assembly that references it.
  • protected
    -Access is limited to within the class definition and any class that inherits from the class.
    -The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
  • internal
    -Access is limited exclusively to classes defined within the current project assembly.
    -The type or member can be accessed only by code in the same class or struct.
  • private
    -Access is limited to within the class definition; This is the default access modifier type if none is formally specified.
    -The type or member can be accessed by any code in the same assembly, but not from another assembly.


There are 5 types access modifiers in dotnet, Those are :-

Private = Accessible only within class
protected = Accessible within the class as well as within child class
internal = Accessible within the same project
protected internal = Accessible within project and child class out side project
public = Accessible every where



也尝试此链接
C#访问修饰符快速参考 [



try this link also
C# Access Modifiers Quick Reference[^]


public:该类型或成员可以由同一程序集或引用该程序集的另一个程序集中的任何其他代码访问.
private:类型或成员只能由相同类或结构中的代码访问.
protected:类型或成员只能由相同类或结构中的代码或从该类派生的类中的代码访问.
内部:类型或成员可以由同一程序集中的任何代码访问,但不能从另一个程序集访问.
protected internal:类型或成员可以由声明该类型或成员的程序集中的任何代码访问,也可以从另一个程序集中的派生类中进行访问.来自另一个程序集的访问必须在从声明受保护内部元素的类派生的类声明中进行,并且必须通过派生类类型的实例进行.

检查MSDN链接.
http://msdn.microsoft.com/en-us/library/ms173121.aspx [ ^ ]

如果您想了解一些新功能,则总是有msdn,Vb,c#
public : The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private: The type or member can be accessed only by code in the same class or struct.
protected: The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal: The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

Check MSDN link.
http://msdn.microsoft.com/en-us/library/ms173121.aspx[^]

There is always msdn if you want to know some new functions, concepts with examples in both Vb,c#


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

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