overload: methods with the same name in the same class. They have different numbers of parameters or different parameter types. It is used for the implementation of methods with the same name but different numbers of parameters or types in the same class, that is, to make the methods have different signature versions. Different parameters are used for distinguishing.
Public string S ()
{< br> return " ";< BR >}< br> Public int S () // error reported. A method named" S "with the same method signature has been defined.
{< br> return 1 ;< BR >}< br> Public int S ( string T) // correct, different method signatures
{
return 1 ;
}
Override: Method overwrite. Defining a method in a subclass has the same name and parameters as its parent class. When the subclass object uses this method, the definition in the subclass is called. For this method, the definition in the parent class is "blocked. This keyword cannot be used to override non-virtual and static methods. The keywords used with this keyword are virtual, abstract, and override. At the same time, the override method cannot modify the accessibility of the virtual method. The override method and the virtual method must have the same access modifier, you cannot use modifiers new, static, virtual, or abstract to modify the override method. If the method is virtual and the subclass uses override, the compiler produces additionalCode. Then, during running, check the class of the object and call the method of the class.
Virtual: the virtual keyword allows you to override these objects in a derived class. By default, the method is non-virtual and cannot be rewritten, virtual keywords cannot be used with static, abstract, private, or override. The virtual keyword is closely related to override. To implement the virtual method, you must use the override or New Keyword (new and override generate different mechanisms ).
Conclusion: The New Keyword is mainly used to distinguish between a derived class and a method with the same name as the base class. By hiding the base class method, the compiler can call the correct method. Override is mainly used
And virtual methods.