C # access modifier

Source: Internet
Author: User

In C #, there are five access modifiers: private, protected, internal, and public) and protectde internal (only the types in this program or inherited from this class can be accessed ).

Objects modified with access modifiers include namespace (namespace), class (class), struct (structure), enum (enumeration), interface (interface), and delegate (delegate) and their members. Next we will explain it one by one.

1. namespace: it has an implicit public category and cannot be explicitly added with any access modifier. However, the namespace member function has the public or internal access level.

2. Enumeration members: Like namespaces, only public access levels are available, and access modifiers cannot be added to enumeration members.

3. struct and class: When only included in namespace, the default value is internal level, which can be displayed as adding public and internal for it; when included in a class, it can be a protected or private modifier.

4. delegate: The default value is internal.

5. interface: different from the class, the interface has the internal level by default. The interface can also be declared as public or internal.

6. Class Members: there are 5 access levels. The default value is private.

7. structure members: public, private, and internal access level. The default value is private, because the structure is implicitly closed. Because the structure does not have an inheritance relationship, you cannot use protected or protected internal to modify the structure members.

8. Interface members: Same as enumeration members, they have the public level, but cannot be explicitly added with the public keyword.

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.