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。

c# 的默认访问修饰符小结(转)的更多相关文章

  1. C#中的默认访问修饰符

    1.命名空间下的元素的默认访问修饰符 public : 同一程序集的其他任何代码或引用该程序集的其他程序集都可以访问该类型或成员.internal : 同一程序集中的任何代码都可以访问该类型或成员,但 ...

  2. C#的默认访问修饰符

    Classes and structs that are not nested within other classes or structs can be either public or inte ...

  3. C# 默认访问修饰符

    c# 中类,成员,枚举,结构等默认访问修饰符是? 根据MSDN文档有: [MSDN] Classes and structs that are not nested within other clas ...

  4. C#中方法、类等的默认访问修饰符~

    C# 方法默认访问级别 : private C# 类默认访问级别 : internal 1.命名空间下的元素的默认访问修饰符 public : 同一程序集的其他任何代码或引用该程序集的其他程序集都可以 ...

  5. C# 方法、类等的默认访问修饰符

    C# 方法默认访问级别 : private C# 类默认访问级别 : internal 1.命名空间下的元素的默认访问修饰符 public : 同一程序集的其他任何代码或引用该程序集的其他程序集都可以 ...

  6. c# 的默认访问修饰符(转)

    c# 的访问修饰符是private 还是 internal? 准确的说,不能一概而论. 类(class)或结构(struct)如果不是在其它类或结构中的话,它的访问类型要不就是internal, 要不 ...

  7. 编写高质量代码改善C#程序的157个建议——建议140:使用默认的访问修饰符

    建议140:使用默认的访问修饰符(我不太赞成作者的这个观点,这样减少的代码基本可以忽略不计,但是,如果把访问修饰符补充完整,反而会使代码更加易读.我认为自己写代码时应该尽量加上访问修饰符,看别人写的代 ...

  8. C#基础回顾(一)—C#访问修饰符

    一.写在前面的话 好久没有停下来总结自己,转眼间15年过去好些天,回首过去的日子,亦或失去,亦或所得!生活的节奏,常常让我们带着急急忙忙的节奏去追赶,也许这并不是每个人所期望的生活方式!于他人,于自己 ...

  9. C# JAVA成员访问修饰符比较

    在面向对象的访问修饰符中常用的有public ,private ,protected C# 访问修饰符: private < protected internal < internal/p ...

随机推荐

  1. 461. Hamming Distance Add to List

    // 快速法求1的个数 int BitCount2(unsigned int n) { unsigned ; ; n; ++c) { n &= (n -) ; // 清除最低位的1 } ret ...

  2. BZOJ4195:[NOI2015]程序自动分析

    浅谈并查集:https://www.cnblogs.com/AKMer/p/10360090.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php? ...

  3. 使用批处理自动发布IIS站点,基于IIS7及以上

    经过研究,终于使用批处理解决了站点发布步骤多的问题. 完整批处理如下: @set "sitePath=%~dp0" @echo 新建程序池 @C:\Windows\System32 ...

  4. java写出进程条代码

    package com.ds; import java.awt.Color; import java.awt.Toolkit; import javax.swing.ImageIcon; import ...

  5. Rails:Rails使用sqlite3数据库 及数据操作基本命令

    Rails默认使用sqlite3做为数据库,虽然很多人更喜欢mysql.但如果是学习用,sqlite3够了,因为它轻量,不需要安装. 首先对sqlite3做个简短的介绍:1.sqlite3不需要配置, ...

  6. 2010.1.1 CLR 无法从 COM 上下文

    今天做一个程序,sql操作,但是记录数太多,而且sql语句有复杂,就报了这样的错误: CLR 无法从 COM 上下文 0x645e18 转换为 COM 上下文 0x645f88,这种状态已持续 60 ...

  7. 2015.4.25利用UIAutomation 替代API函数,解决了ListView无法读数据的难题,顺便实现了鼠标模拟滚轮

    UIAutomation比API的优点是类似于消息处理机制,而不是主要靠模拟鼠标键盘发送消息 首先添加引用UIAutomationClient和UIAutomationTypes,在安装.net3.5 ...

  8. 第九章 Java中线程池

    Java中的线程池是运用场景最多的并发框架,几乎所有需求异步或并发执行任务的程序都可以使用线程池.在开发过程中,合理地使用线程池能够带来3个好处. 降低资源消耗:通过重复利用已创建的线程降低线程创建和 ...

  9. Dataguard ORA-19909 ORA-01110

    在创建ORACLE 10G Dataguard时,报错: Datafile 1 (ckpscn 24967685451) is orphaned on incarnation#=6 MRP0: Bac ...

  10. 新增线下、APP、公众号多处入口,小程序会再火起来么?

    现在,大多数互联网创业者最缺的是流量,第二缺的是钱.之前开发者们追捧小程序的重要原因就是在于认为这可能是下一个微信公众号体量的流量入口,因为大家都想从微信的8亿多用户中收获自己的一部分用户. 近期部分 ...