Internal access level [C #]

Source: Internet
Author: User

Internal is added to the front of the class so that only the same assembly file can be referenced. The common use of internal is based on component development, which facilitates communication between components without exposing the structure to the outside world.

Routines inside, assembly1 defined BaseClass is a internal class, after the output becomes DLL, assembly2 come to reference it, this time again to want to quote internal class will not be.

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

A common use of internal access was 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 usin G members with internal access. Since these members were internal, they was not exposed to code that was 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 is overridden in some languages, such as textual Microsoft intermediate language (M SIL) 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 the files, Assembly1.cs and Assembly2.cs. The first file contains an internal base class, BaseClass. In the second file, a attempt to access the member of the base class would produce an error.

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

-file Assembly2.cs

// Assembly2.cs// compile with: /reference:Assembly1.dll// CS0122 expectedclass TestAccess {   public static void Main()    {      BaseClass myBase = new BaseClass();   // error, BaseClass not visible outside assembly   }}

Internal access level [C #]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.