Class modifiers: public, internal, partial, abstract, sealed, static
Member modifier: public, protected, private, internal, sealed, abstract, virtual, override, ReadOnly, const
Public: Most open, all of this assembly and other objects inside the assembly can access
Protected: More open, self-member and subclass member accessible
Private: Only its members can access
Internal: Members within this assembly can access
Partial: Some classes can be divided into parts of a class in different files, the final compilation will be merged into one file, and the parts can not be scattered in different assemblies
Abstract: When a class is decorated, it indicates that the class is an abstract class and cannot create an instance of the class. When the method is modified, the method needs to be implemented by subclasses, and if the subclass does not implement the method then the subclass is also an abstract class, and the class containing the abstract method must be an abstract class.
Sealed: When a class is decorated, it means that the class cannot be inherited, and the method is decorated to indicate that it cannot be overwritten.
Static: When a class is decorated to represent the class when it is not able to instantiate an object of that class, and since the class cannot be instantiated, then the class cannot contain an object member, that is, all members of the class are static, and when a class member is decorated, the member is a class member and can only be accessed through the class. Member name method.
When the static modifier constructor, the constructor cannot contain any arguments, cannot contain modifiers, the constructor cannot enter the object member
The line initialization operation. However, it is possible to initialize or invoke static members. There is no guarantee of when he will execute, but to ensure that the class is used for the first time
Type before execution. The static member that is initialized in the static constructor is the final initialization result. For example:
View Plain
public static int test = 0;
Static person ()
{
Test = 3;
}
static void Main (string[] args)
{
Console.WriteLine (person.test);//Run result is 3
}
Note: When a class or method is not decorated with any modifiers, the default is internal:
C # uses a variety of modifiers to express the different properties of a class. There are five different restriction modifiers for classes based on their protection level C #:
Public can be arbitrarily accessed;
Protected can only be accessed by this class and its inheriting subclasses;
Internal can only be accessed by all classes within the group (Assembly), which are logical units and physical units of the class being combined in the C # language.
The compiled file name extension is often ". DLL "or". EXE ".
Protected internal is the only combination restriction modifier that can be accessed only by all classes in the group and by the inherited subclasses of those classes.
Private can only be accessed by this class.
If the class is not nested, the namespace or the class within the compilation unit has only public and internal two adornments.
The new modifier can only be used for nested classes, which represent shadowing of a type with the same name inherited from the parent class.
Abstract is used to decorate a class, indicating that the class can be used only as a parent class for inheritance, not object instantiation. Abstract classes can contain abstract
But this is not a must. Abstract cannot be used in conjunction with new.