Asp.net modifier introduction (about public, private, protected, internal), protectedinternal

Source: Internet
Author: User

Asp.net modifier introduction (about public, private, protected, internal), protectedinternal

1. private Modifier

The private modifier is used to set the access permission of a class or class member to the internal of the class,
Private is also called a private modifier. You can use the get and set accessors to read or modify private class members.

2. protected Modifier

The protected modifier is used to set the access permissions of a class or class member to the class and its subclass.

3. internal Modifier

The access permission of the class or class member modified by internal modifier is within the same assembly, and the default class access modifier of C # is internal.

4. public Modifier

The public modifier is the public access permission, which has no restrictions on code access,
In most cases, you must exercise caution when using the public modifier because misuse affects the encapsulation of classes and brings security risks.

Declared accessibility Significance
Public access is unrestricted.
Protected access is limited to include classes or types derived from include classes.
Internal access is limited to the current project
Protected internal access is limited to the current project or type derived from the include class
Private access is limited to include type only


Brief Introduction to access permissions of private, protected, public, and internal Modifiers

Private: a private member that can be accessed within the class.
Protected: protects members, which can be accessed within the class and in the inheritance class.
Public: A public member. It is completely public and has no access restrictions.
Internal: accessible within the same namespace.

ASPNET> How do I use protected, internal, and private? Even unclear

Private: members modified by this modifier can only be accessed within the class. Even if an instance of this class is declared elsewhere, members modified by this modifier cannot be accessed.
Protected: members modified by this modifier can be accessed inside the class and the subclass of the current class.
Internal: members modified by this modifier can be accessed in the same namespace.

Related Article

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.