1. In. net, inheritance is not related to languages. Classes written in one hosting language can inherit classes written in another hosting language.
Cross-language inheritance must ensure that both the base class and the derived class comply with the common language specification (CLS)
2. The first parameter of the extension method must be this, followed by the target type, which specifies where the extension method can be applied.
If the instance method and the extension method have the same signature, the instance method is called.
If the two extension methods have the same signature, one of them must be called as a normal static method.
The static class to which the extension method belongs must be in the scope. Otherwise, the extension method cannot be called.
3. for virtual methods, the compiler prefers to call underlying derived methods.
4. the constructors and destructor of the base class are not inherited by the derived class. For a derived class object, the default constructor of the base class is called by default to initialize the status of the base class. If the base class does not have a default constructor, a compilation error occurs unless the derived class calls a constructor with parameters of the base class.
5. Comparison between interfaces and abstract classes
Abstract classes can contain some implementations, but interfaces are not fully implemented.
Abstract classes can inherit other interfaces and classes, while interfaces can only inherit other interfaces.
The abstract class can contain fields, and the interface is stateless.
Abstract classes include constructor and destructor. Neither of the interfaces is available.
Interfaces can be inherited by structures, and abstract classes cannot be inherited by structures.
6. the descendant of a derived class that implements an interface cannot be forcibly converted to this interface type. Only the type that directly implements an interface can be forcibly converted to this interface type. However, the child of this class can be forcibly converted to the type of this interface through the parent class
Explicitly implemented interface members cannot be overwritten in child types
7. The two benefits of polymorphism are late binding and scalability.
8. There are three factors for Polymorphism:
Related Classes
Common Methods
Different behaviors
9. Interface Polymorphism
10. The base class or interface can be used as a function parameter or return value. It can provide polymorphism behavior in the called function and the called function respectively. The reasons for using a base class or interface as a parameter or return value are as follows:
Generalized function call or return value. Function parameters or returned values can use different but related types.
The specific parameters or return types may not be known during compilation. The base reference supports late binding and the type is selected at runtime (polymorphism)
The returned base class or interface restricts access to the object. This is particularly useful for class libraries that want to hide a part of a public interface.
11,