How and when to use Shadows
and Overrides
? What are the usage recommendations for each and in what context do you use them?
In a way it's already answered in How does "new" and "virtual" work in C #? . Only that there is C #.
Overrides
in VB.Net is the same as override
of C #. E Shadows
is the same as new
as modifier of a method.
Summarizing what's already in the C # response:
Overrides
tells the compiler you want to overwrite the implementation of a virtual method declared in the base class used in the current inheritance. So you can only use if the class is inheriting from another and have a virtual method in it with same signature than method you are writing in the new class. That is, you want to polymorphically replace the existing method.
Shadows
does something that seems to be the same , but in fact it overlaps the method that is in the base class. He says to ignore that method and use that one. In theory the language could do this without any modifier so much that its use is not mandatory, but the compiler asks you to put something to say you know what you are doing and it is intentional. This avoids mistakes by carelessness.
The consequences of this can be seen in the explanation of the C # linked question above.
Reading the linked documentation (in your keywords) is critical to fully understanding the use of them.