The default access decoration in the c#
The default access modifier in C# follows one principle: the accessability setting of each member is "the most restricted access permissions you can declare for the member".
Specifically, the default access to different entities in C# is as follows:
Class (CLASSSES):
internal
private
private
private
interface (interfaces): private
For example, the following code represents an external class called public
Outer
One of the exceptions of this rule is when you define different accessibility for different parts of the attribute (usually setter). For example: Inner
Foo()
<code class="language-csharp">namespace MyCompany { class Outer { void Foo() { } class Inner { } } }</code>
Namespaces:
<code class="language-csharp">namespace MyCompany { internal class Outer { private void Foo() { } private class Inner { } } }</code>
Type (Types):
(in the compilation unit or name space)<code class="language-csharp">public string Name { get { ... } private set { ... } // 显式设置为 private }</code>
Class Members:
public
(because the structure is sealed) internal
private
The above is the detailed content of What Are the Default Access Modifiers for Classes, Members, and Other Entities in C#?. For more information, please follow other related articles on the PHP Chinese website!