Let's talk about the four access permission modifiers in C #.

Source: Internet
Author: User

I think everyone knows this four modifiers very well, but here I still want to say, why? Because each person has different understandings of it, I wrote a story about myself and shared it with everyone. I hope you can point out something wrong or something you need to talk about.

C # Class and Class Member modifiers include the following five:
Public Class and Class Member modifiers have no level limit on access members
Modifier of private class members can only be accessed within the class
The modifier of protected class members can only be accessed in the class and its derived classes, regardless of whether the derived class and the base class are in the same assembly
Accesses to internal classes and class member modifiers within internal are limited
What does protected internal mean internally protected? Note: If the diagram shows an inherited link, it can be accessed in the same set of programs or not. If it is not an inherited link, it can only be accessed in the same set of programs.

Class access permissions:
Only public and internal modifiers can be placed before the class. If no modifier is written, the default modifier is internal.
Let's first talk about the class access permission: 1: public class: This class can be accessed anywhere; 2: internal class: only in the same assembly (you can understand it as follows: if you have created a solution with three projects, there will be three sets. If you set a class in the first project to internal class, therefore, it is impossible for the second project to call this class because it is not in the same assembly.) This class can be accessed;

Access Permissions of class members:
The access permissions of class members can be composed of four modifiers: public, private, protected, internal, and protected internal. If no modifier is written before class members, the default value is private.

I found a picture on the Internet for their access permissions. I posted this picture, which shows the access permissions of class members.

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/menglin2010/archive/2010/12/04/6054483.aspx

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.