c#public_private_protected_internal_protected Internal

Source: Internet
Author: User

The Private keyword is a member access modifier, and private access is the lowest level allowed for access, and private members are only accessible to the class and struct in which they are accessed.

For example, in the following example, the Employee class contains two private data members, name and salary, and private members can only be accessed through member methods, so a public method named GetName and salary is added, allowing access to the private member to be controlled. The name member is accessed through public methods, and the salary member is accessed through a public read-only property.

usingSystem;classemployee{Private stringName ="FirstName, LastName"; Private DoubleSalary =100.0;  Public stringGetName () {returnname; }     Public DoubleSalary {Get{returnsalary;} }}

The Public keyword is a type and type member access modifier, which is the highest level of access allowed, with no restrictions on access to public members.

The protected keyword is a member access modifier, and access is limited to types that are derived from the containing class and the containing class.

The internal keyword is an access modifier for a type and a member of a type, and only the internal type or member is accessible in a file of the same assembly.

This is the description of internal on MSDN, with the types enum (enum), Class (classes), Interface (interface), struct (struct).

Type members have functions, member variables such as functions and member variables, and so on.

Protect internal can only be used in this class, derived classes, or assemblies that contain the class.

c#public_private_protected_internal_protected Internal

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.