zoukankan      html  css  js  c++  java
  • C#的默认访问修饰符

    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。

    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。

  • 相关阅读:
    Log4Net 生成多个文件、文件名累加解决方法
    HTML name、id、class 的区别
    C# 基础(一) 访问修饰符、ref与out、标志枚举等等
    HTML iframe 和 frameset 的区别
    未在本地计算机上注册"OraOLEDB.Oracle"提供程序
    HTML 页面源代码布局介绍
    HTML 基础控件介绍
    图的BFS与DFS的应用
    迷途指针,从百度百科上摘抄的,语言很幽默
    详解C中volatile关键字
  • 原文地址:https://www.cnblogs.com/action98/p/3483895.html
Copyright © 2011-2022 走看看