C # use a variety of modifiers to express the different properties of the class. Class C # of its protection level has five different restrictions and modifiers:
Public can be accessed at will;
Protected can only be accessed by this class and its inherited sub-classes;
Internal can only be accessed by all classes in the Assembly. The combination is the logical unit and physical unit after the classes in C # language are combined, the compiled file extension is often ". DLL or. EXE ".
Protected internal is a unique composite modifier that can only be accessed by all classes in the current composite and the inherited sub-classes of these classes.
Private can only be accessed by this class.
If it is not a nested class, only the public and internal classes in the namespace or compiling unit are modified.
The new modifier can only be used for nested classes, indicating hiding the type that inherits the same name of the parent class.
Abstract is used to modify abstract classes, indicating that the class can only be used as the parent class for inheritance, but cannot be instantiated. Abstract classes can contain abstract members, but they are not required. Abstract cannot be used together with new. The following is the pseudo code used in the abstract class:
Abstract Class
{
Public abstract void F ();
}
Abstract class B:
{
Public void g (){}
}
Class C: B
{
Public override void F ()
{
// Implementation of method F
}
}
Abstract class A contains an abstract method F (), which cannot be instantiated. Class B inherits from Class A, which contains an instance method g (), but does not implement the abstract method F (), so it must still be declared as an abstract class. Class C inherits from Class B and implements class abstraction method F (). Therefore, objects can be instantiated.
Sealed is used to modify a class as a sealed class to prevent the class from being inherited. At the same time, abstract and sealed modifications to a class are meaningless and prohibited.