Summary of default access modifiers for C #

Source: Internet
Author: User
Tags modifiers

Is the access modifier for C # private or internal?

To be exact, it cannot be generalize.

[MSDN]

Classes and structs that is not nested within other Classes or structs can is either public or internal. A type declared as public are accessible by any other type. A type declared as internal is only accessible by types within the same assembly. Classes and structs are declared as internal by default unless the keyword public is added to the class Definitio N, as in the previous example. Class or struct definitions can add the internal keyword to make their access level explicit. Access modifiers does not affect the class or struct itself-it always have access to itself and all of its own members.

If the class or struct (struct) is not in another class or struct, its access type is either internal or public;

In other words, if it is in another class or struct, it can be private or protected, and so on. The class and structure I'm talking about, if no special instructions, mean "class in class"

The default access type for a class or struct is internal.

All members of the class, by default, are private.

[MSDN]

Interfaces, like classes, can is declared as public or internal types. Unlike classes, interfaces default to internal access. Interface members is always public, and no access modifiers can is applied.

Namespaces and enumeration members is always public, and no access modifiers can is applied.

Delegates has internal access by default.

Any types declared within a namespace or at the top level of a compilation unit (for example, not within a namespace, Clas s, or struct) is internal by default, but can is made public.

Interface default accessor is internal

The member default access modifier for an interface is public and cannot be another access modifier

namespace, enum type member default public, and cannot be other access modifiers

delegate, default internal

All types inside the namespace or at the top of the compilation unit, default is internal, and can be changed to public manually.

Summary of default access modifiers for C # (GO)

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.