About public, private, protected, and internal

Source: Internet
Author: User

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 Meaning
Public Unrestricted access
Protected Access is limited to include classes or types derived from include classes
Internal Access is limited to the current project only
Protected internal Access is limited to the current project or type derived from the include class.
Private Access is limited to include type only

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.