4 access modifiers in C #

Source: Internet
Author: User

The following five modifiers for class and Class members in C # are as follows:
Public exposes class and class members with no level restrictions on access members
The modifiers of private class members can only be accessed within the class
Protected the modifier of a protected class member can only be accessed in that class and in a derived class of that class, regardless of whether the derived class and base class are in the same assembly
Internal inside class and class members are restricted to assemblies
Protected internal What do you mean by the protected interior? Note that if the image is an inheritance relationship, whether it is accessible in the same assembly or not, it can only be accessed in the same assembly if it is not an inheritance relationship

The access rights of the class:
Modifiers that can be placed before class classes are only public and internal, and if no modifiers are written, the default is internal
Let's start with the access to the class: 1:public class: Anywhere the class can be accessed; 2:internal class: Only within the same assembly (you can understand this: if you build a solution with three projects in it, there are three assemblies, If you set a class in the first project to internal class, then it is not possible for the second project to call this class, because it is not in the same assembly, it can be accessed;

Access rights for Class Members:
The access rights of a class member can consist of four modifiers: public,private, protected,internal,protected internal; If no modifier is written before the class member, the default is private.


Their access rights I found a picture on the internet, and I posted this picture, which is a good illustration of the access rights of class members.

4 access modifiers in C #

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.