zoukankan      html  css  js  c++  java
  • internal 访问级别 [c#]

    internal加在类的前面,这样一来只有同一个assembly的文件间才可以引用。internal常见用途就是基于组件的开发,方便组件间通讯,又不会将结构暴露给外界。

    例程里面,assembly1定义的BaseClass是一个internal类,在输出成为dll以后,assembly2过来引用它,这个时侯再来想引用internal的class就不行了。

    The internal keyword is an access modifier for types and type members. Internal members are accessible only within files in the same assembly. For more information on assemblies, see Components and Assemblies.

    A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code. For example, a framework for building graphical user interfaces could provide Control and Form classes that cooperate using members with internal access. Since these members are internal, they are not exposed to code that is using the framework.

    It is an error to reference a member with internal access outside the assembly within which it was defined. Caution An internal virtual method can be overridden in some languages, such as textual Microsoft intermediate language (MSIL) using Ilasm.exe, even though it cannot be overridden using C#.

    For a comparison of internal with the other access modifiers, see Accessibility Levels.

    Example

    This example contains two files, Assembly1.cs and Assembly2.cs. The first file contains an internal base class, BaseClass. In the second file, an attempt to access the member of the base class will produce an error.

    • File Assembly1.cs:
    // Assembly1.cs
    // compile with: /target:library
    internal class BaseClass 
    {
       public static int IntM = 0;
    }
    

    -File Assembly2.cs

    // Assembly2.cs
    // compile with: /reference:Assembly1.dll
    // CS0122 expected
    class TestAccess 
    {
       public static void Main() 
       {
          BaseClass myBase = new BaseClass();   // error, BaseClass not visible outside assembly
       }
    }
    
  • 相关阅读:
    B. Connecting Universities DFS,无向树
    HDU 5808 Price List Strike Back bitset优化的背包。。水过去了
    uva 6910
    HDU 5778 abs 数学
    Invitation Cards POJ 1511 SPFA || dij + heap
    HDU 2243 考研路茫茫——单词情结 求长度小于等于L的通路总数的方法
    cmd链接mysql
    如何设置远程访问mysql
    ERROR 1045 (28000): Access denied for user'root'@'localhost'(using password:YES)51Testing软件测试网-H*?U)}$h }P6H4H
    String ,StringBuffer,StringBuilder的区别(转)
  • 原文地址:https://www.cnblogs.com/SiumingLearning/p/4375997.html
Copyright © 2011-2022 走看看