• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c#的默认访问修饰符小结(转)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

c# 的访问修饰符是private 还是 internal?

准确的说,不能一概而论。

[MSDN]

Classes and structs that are not nested within other classes or structs can be either public or internal. A type declared as public is accessible by any other type. A type declared as internal is only accessible by types within the same assembly. Classes and structs are declared as internal by default unless the keyword public is added to the class definition, as in the previous example. Class or struct definitions can add the internal keyword to make their access level explicit. Access modifiers do not affect the class or struct itself — it always has access to itself and all of its own members.

类(class)或结构(struct)如果不是在其它类或结构中的话,它的访问类型要不就是internal, 要不就是public;

换句话说,如果它在其它类或结构中的话,则可以为private 或protected等。下面我说的类和结构,如无特殊说明,均指非"类中类"

类或结构的默认访问类型是internal.

类中所有的成员,默认均为private。

[MSDN]

Interfaces, like classes, can be declared as public or internal types. Unlike classes, interfaces default to internal access. Interface members are always public, and no access modifiers can be applied.

Namespaces and enumeration members are always public, and no access modifiers can be applied.

Delegates have internal access by default.

Any types declared within a namespace or at the top level of a compilation unit (for example, not within a namespace, class, or struct) are internal by default, but can be made public.

接口默认访问符是internal

接口的成员默认访问修饰符是public,也不可能是其他访问修饰符

命名空间,枚举类型成员默认public,也不可能是其他访问修饰符

委托,默认internal

在命名空间内部或编译单元顶部的所有类型,默认是internal,可以人为改为public。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#网络编程中的异常处理发布时间:2022-07-14
下一篇:
c#设计模式之装饰者模式发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap