The C # language is specially designed so that version control between the base classes and derived classes in different libraries can continue to develop and maintain backward compatibility. This has many meanings. For example, this means that introducing a new member with the same name as a member in the derived class in the base class is fully supported in C # and will not cause unexpected behavior. It also means that the class must explicitly declare whether a method needs to override an inherited method or a new method that only hides an inherited method with a similar name.
C # Allow the derived class to contain methods with the same name as the base class method.
The base class method must be defined as virtual.
If the method in the derived class does not have the new or override keyword before it, the compiler will issue a warning that the method will execute the operation like there is a new keyword.
If the method in the derived class has a new keyword before it, the method is defined as a method independent from the method in the base class.
If the method in the derived class has the override keyword before it, the object of the derived class will call this method without calling the base class method.
You can use the base keyword in the derived class to call the base class method.
The override, virtual, and new keywords can also be used in attributes, indexers, and events.
By default, the C # method is not a virtual method. If a method is declared as a virtual method, any class that inherits the method can implement its own version. To make a method a virtual method, you must use the virtual modifier in the method declaration of the base class. Then, the derived class can use the override keyword to override the basic virtual method, or use the new keyword to hide the virtual method in the basic class. If the override keyword and New Keyword are not specified, the compiler will issue a warning and the methods in the derived class will hide the methods in the base class.