The default access decoration in the C#
C# roy the default access to the class, methods and other members, and the protection level of its application may be unexpected.
The default access level
The default access modifier in C# is not an explicit statement, but depends on the context. Generally speaking, it awarded the most restricted access permissions
by .For example, in the following code fragment:
The default access modifier is:
<code class="language-csharp">public class Outer { void Foo() {} class Inner {} }</code>
OUTER class: Internet (accessible access to the same program)
attribute is a special situation. Although the attribute itself may have public access permissions, the setter can be explicitly limited:
Here, name can be visited publicly, but the modification permissions are limited to the class itself.Other descriptions
<code class="language-csharp">public string Name { get { ... } private set { ... } }</code>
Naming space has hidden public access rights. Naming space or the type in the compilation unit defaults to the Internet access permissions.
The above is the detailed content of What Are the Unexpected Default Access Modifiers in C#?. For more information, please follow other related articles on the PHP Chinese website!