Internal (C # reference)

Source: Internet
Author: User

QuiltInternalModifierOnlyUsed in this Assembly (current project.

QuiltProtected internalThe modified attributes/methods can beDerived classUse

For example, app1 and app2.

App1 is the startup project, while app2 is only a class library

 

/* Project app2 */

Namespace app2

{

Internal class cinternal // This class can only be used in app2 (the entire class is internal, equivalent to all attributes are also internal ){

Public int A; // only app2 can be used.

Internal int B; // same as above, only available in app2

}

Public class vinternal // This class can be used in app1 (as long as app2 is referenced), but internal-modified attributes/methods in this class cannot be used in other projects other than app2 {

Internal int A; // can only be used in app2

Protected internal int B; // It Can Be Used in app2. it cannot be used directly in app1, but it can be used by classes inherited from this class in app1.

Public int C; // use protected internal void display () in app1 app2, which cannot be used directly in app1, however, it can be used by classes inherited from this class in app1. {Console. writeline ("Hello protected internal ");}}

} // Namespace app2

/* Project app1 */

Using app2;

Namespace app1 {

Class app1 () {app2.cinternal internalclass = new app2.cinternal ();//!!! Error !!! -Cinternal is modified by internal and can only be used in app2.

& Nbsp; app2.vinternal internalvar = new app2.vinternal (); // OK-vinternal is public and can be used anywhere

& Nbsp; internalvar. A = 100 ;//!!! Error !!! -Modified by internal, which can only be used in app2

& Nbsp; internalvar. B = 100 ;//!!! Error !!! -It is modified by protected internal and cannot be used directly in external projects.

& Nbsp; internalvar. c = 100; // OK

Internalvar. Display ();//!!! Error !!! -It is modified by protected internal and cannot be used directly in external projects.

} // Classapp1

& Nbsp; Class inheritfrominternal: app2.vinternal // inherits the vinternal, so you can use the attribute {base. A = 100 ;//!!! Error !!! -Attributes modified to internal can only be used in app2.

Base. B = 100; // OK-attributes modified as protected internal can be used by the derived class.

Base. Display (); // OK-attributes modified to protected internal can be used by the derived class.

} // Classinheritfrominternal

} // Namespace app1

 

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.