• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅

访问修饰符(C# 编程指南)(链接)

下面这篇微软官方文档,介绍了C#中的public、private、protected、internal等访问修饰符:

Access Modifiers (C# Programming Guide)

 

文档中有两个地方,这里特别强调下:

Classes and structs declared directly within a namespace (in other words, that aren't nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.

也就是说,在命名空间下的一个类或结构体,如果没有声明访问修饰符,那么类或结构体的默认访问修饰符就是internal。

Class and struct members, including nested classes and structs, have private access by default.

也就是说,在类或结构体中定义的成员(包括字段、属性、方法、嵌套的类或结构体等),如果没有声明访问修饰符,那么成员的默认访问修饰符就是private。

 

posted @ 2020-04-22 13:59  PowerCoder  阅读(272)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3