C # access level restrictions for classes and Methods

Source: Internet
Author: User

Class:

Class access modifiers include public and Internal. The default value is internal.

Internal restriction class access in this project and cannot be accessed by other projects

Public allows the class to be accessed in other projects, but you must first Add a reference to the project where the class is located and use the namespace of the class;

Method:

Method access modifiers include private, protected, internal, public, and protected internal. The default value is private.

The private method is restricted to access in this class and cannot be accessed in other classes and projects of this project.

Protected restricts the access of methods in this class and its sub-classes, including the sub-classes of external projects (direct call, without instantiation); Non-inheritance class in this project and other projects, and access through instance calls

Internal restricts access to all classes in the project and cannot be accessed by other projects.

Public allows the method to be accessed in other projects, but you must first Add a reference to the project where the method is located, and the namespace of the using class;

** Protected internal allows the method to be accessed in all classes of the project that have an inheritance relationship with the external project. Actually, the union of the two ranges is used. Note that this is not an intersection.

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.