Default access modifiers in C #

Source: Internet
Author: User

1. Default access modifiers for elements under namespaces

Public: Any other code of the same assembly or other assemblies that reference the assembly can access the type or member.
Internal: Any code in the same assembly can access the type or member, but other assemblies cannot be accessed.

2. Default access modifiers for members in each type
The remaining modifiers are primarily positive to inherit the language attribute, with inherited types having two classes (class) and Interfaces (interface). Public,internal can also be used for type members.
Private: Code of the same class and struct can access the type and members.
Protected: Code in the same class and derived (inherited attribute) classes can access the type and members.
Protected internal: Any code in the same assembly or any derived class in another assembly can access the type or member.

MSDN Tips:
1.) The accessibility of a derived class cannot be greater than its base type. In other words, there cannot be a public class B derived from the inner Class A. If this is allowed, a becomes a public class, because all protected members of a and internal members can be accessed from derived classes.
2.) The accessibility of a member must not be greater than the accessibility of its containing type.
3.) You can declare class members (including nested classes and structs) using either of the five access types.

Interface (interface)
The interface member access adornment defaults is considered public and cannot be displayed using the access modifier.

Classes (Class)
The constructor defaults to the public access modifier.
Destructors cannot be displayed using the access adornment Fu Gingme to consider the private access modifier.
The default access modifier for a member of a class is private;

Enum (enum)
Enumeration type members default to the public access modifier and cannot be displayed using modifiers.

Structure (struct)
The struct member defaults to the private modifier.
Struct members cannot be declared as protected members, because structs do not support inheritance.

Nested types
The default access modifier for a nested type is private. And class, the members of the struct have the same type of default access

Default access modifiers in C #

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.