How and when to use "Shadows " and"Overrides"?

How and when to use Shadows e Overrides? What are the recommendations for use for each and in what context to use them?

Author: Maniero, 2016-09-09

1 answers

In a certain way is already answered in How does "new" and "virtual" work in C#?. Only there is C#.

Overrides no VB.NET it's the same override as C#. And Shadows is the same as new as a method modifier.

Summarizing what is already in the C # answer:

Overrides tells the compiler that you want to overwrite the implementation of a virtual method declared in the base class used in the current inheritance. So it can only use in case the class is inheriting of another and have a virtual method in it with the same signature as the method you are writing in the new class. That is, you want to polymorphic replace the existing method.

Shadows it does something that seems to be the same, but in fact it overlays the method that is in the base class. It says to ignore that method and use that one. In thesis the language could do this without any modifiers, so much so that its use is not mandatory, but the compiler asks that you put something to say that you know what you're doing and it's intentional. So avoid mistakes by carelessness.

The consequences of this can be seen in the explanation of the C # question linked above.

Reading the documentation linked (in the keywords) is critical to fully understand their use.

Comparison Shadows X Overrides

 4
Author: Maniero, 2020-11-09 13:52:39