C # differences between public private protect

Source: Internet
Author: User

The public keyword is an access modifier for type and type members. Public access is the highest allowed access level, and there is no restriction on access to public members.
The protected keyword is a member access modifier. Protected members can be accessed in their classes and can be accessed by Derived classes.
The private keyword is a member access modifier. Private access is the minimum allowed access level. Private Members are accessible only when their classes and struct are declared.
Internal keywords are access modifiers for type and type members. Internal types or members are accessible only in files of the same assembly.

Public means that all members declared after it can be retrieved from all users.
The private keyword means that no one except the creator of this type and the internal member functions of the class can access these members.
Protect is similar to private. There is only one difference: the inherited structure can access the protected member, but cannot access the private member.

========================================================== =====

Public is visible to all other programs, subprograms, and programs other than the package.
Private is the opposite. It is invisible to anyone except yourself.
Protect is visible to the same package and subprograms
You are the current program.
Which program is your privat variable and method? This program is your own.

========================================================== =====

Public has a good affinity,
Protect is only good for acquaintances,
Private is private.
But they are triplets.
Class is their father.


This article is from the son of the Sea blog, please be sure to keep this source http://4769069.blog.51cto.com/4759069/1215892

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.