This article mainly introduces the use of C # class access modifier, a more detailed analysis of C # class access modifier concept and usage, with a certain reference value, the need for friends can refer to the following
In this paper, the use of access modifiers for C # classes is analyzed in detail and shared for everyone's reference. The specific usage analysis is as follows:
By default, a class is declared internal, which means that only code in the current project can access it. You can explicitly specify it with the internal access modifier keyword, but this is not required and the class is defined by default for this type of class. But the C # method default Access level: Private.
The access level of a method or property's modifier is as follows:
Access modifiers |
Significance |
Public |
Access is unrestricted and can be accessed within the class and in code outside of any class |
Protected |
An accessible domain is scoped to or within a class that derives from that class |
Internal |
Accessible domains are scoped to the assembly in which the class resides |
protected internal |
Protected or internal, accessible domains are scoped to the program in which the class resides or to those classes that derive from the class to which it belongs |
Private |
An accessible domain is limited to the class it belongs to |
Combination of access modifiers that can be used in a class definition
None or internal class can only be accessed in the current project
The public class can be accessed from anywhere
Abstract or internal abstract classes can only be accessed in the current project, cannot be instantiated, only inherit
The public abstract class can be accessed anywhere, cannot be instantiated, and can inherit only
Sealed or internal sealed class can only be accessed in the current project, cannot be derived, can only be instantiated
The public sealed class can be accessed anywhere, cannot be derived, and can only be instantiated
The default access modifiers for methods, classes, and so on in C # are described below
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
I hope this article is helpful to everyone's C # programming.
Source: http://www.jb51.net/article/56597.htm
Access modifiers for C # classes, methods