C # object-oriented key points,
Static MemberIt can be shared among instances of the class, and can be viewed as a global variable of the class. Static attributes and static fields can access data independent from any object instance. Static methods can execute commands related to the object type but not related to the type instance. When using static members, you do not need to instantiate objects.
Static classWhen we want a class to only contain static members and cannot be used to instantiate objects, a simple method is to use static classes (such as the Console) instead of setting the constructor to private. A static class only contains static members. You can have a static constructor without instance constructor.
InterfaceIt is a combination of specific public methods and attributes to encapsulate a set of specific functions for implementing the class that requires interface definition functions. The interface cannot exist independently or be instantiated. The interface cannot contain the implementation code of its members, but can only define members. The implementation process must be implemented in the class that implements the interface.
InheritanceC # and Java are both single inheritance. The inherited classes are called base classes. The Derived classes cannot access private members of the base classes and can access public and protected members. The base class member can be virtual and can be rewritten in the derived class. The class can be sealed, and the sealing class cannot be inherited. All objects in C # Have a common base class object.
PolymorphismThe same command has different responses to different objects, which is polymorphism. Polymorphism is produced by inheritance. Inheritance leads to overlapping methods and attributes between child classes and parent classes. You can use the same syntax to process objects instantiated from the same base class. Objects of a derived class instance can be directly assigned to the Base class object without type conversion. Then, the base class object can call the members of the derived class, but cannot call methods defined by the subclass itself. The interface also has polymorphism.
InternalThe modified class can only be accessed in the code of the current project.
AbstractThe modified class cannot be instantiated and can only be inherited.SealedThe modified class can only be instantiated and cannot be inherited. A class can only have one base class. If an abstract class is inherited, all the abstract members inherited must be implemented (unless the derived class is also abstract ). The compiler does not allow the accessibility of a derived class to be higher than its base class. Abstract and sealed keywords cannot be used in interfaces. The interface does not inherit objects.
Interfaces and abstract classesCan be inherited, and cannot be instantiated, but can declare variables. A derived class can inherit only one abstract class, but multiple interfaces can be used. Abstract classes can have abstract members and non-Abstract members (including code bodies or virtual ones, which can be rewritten in a derived class ). All interface members must be implemented on the class using the interface. The interface cannot contain fields, constructors, destructor, static members, or constants.