Default modifiers in C #

Source: Internet
Author: User

Reference from default visibility for C # classes and Members (fields, methods, etc)?

Classes and structs that is declared directly within a namespace (in other words, that is not nested within other Classe s or structs) can be either public or internal. Internal is the default if no access modifier is specified.

Classes and structs that are directly declared under namespaces are internal by default.

The access level for class members and structs members, including nested classes and structs, are private by default.

Members of classes and structs, including embedded classes and structs, are private by default

Interfaces default to internal access.

The interface is internal by default

Delegates behave like classes and structs. By default, they has internal access when declared directly within a namespace, and private access when nested.

Delegates are similar to classes and structs. Directly declaring access rights under a namespace is internal by default. If it's embedded, it's private.

Top-level types, which is not nested in other types, can only has internal or public accessibility. The default accessibility for these types is internal.

Summary, the highest level of type (not embedded in other types), can only have internal and public access rights. The default access permissions for these types are internal

For embedded types, however,
And for nested types:
Members of the Default member accessibility
---------- ----------------------------
The members of the enum public//enum are public access rights
class private//member, default is private access rights
Interface public//member of interface, default is private access rights
struct private//struct member, similar to class, the default access rights are also private

Default 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.