Partilhar via


Shadows (Visual Basic)

Specifies that a declared programming element redeclares and hides an identically named element, or set of overloaded elements, in a base class.

Comentários

The main purpose of shadowing (which is also known as hiding by name) is to preserve the definition of your class members. The base class might undergo a change that creates an element with the same name as one you have already defined. If this happens, the Shadows modifier forces references through your class to be resolved to the member you defined, instead of to the new base class element.

Both shadowing and overriding redefine an inherited element, but there are significant differences between the two approaches. For more information, see Sombreamento em Visual Basic.

Rules

  • Declaration Context. Você pode usar Shadows somente no nível de classe . This means the declaration context for a Shadows element must be a class, and cannot be a source file, namespace, interface, module, structure, or procedure.

    You can declare only one shadowing element in a single declaration statement.

  • Combined Modifiers. Não é possível especificar Shadows em conjunto com Overloads, Overrides, ou Static na mesma declaração.

  • Tipos de elemento. You can shadow any kind of declared element with any other kind. If you shadow a property or procedure with another property or procedure, the parameters and the return type do not have to match those in the base class property or procedure.

  • Accessing. The shadowed element in the base class is normally unavailable from within the derived class that shadows it. However, the following considerations apply.

    • If the shadowing element is not accessible from the code referring to it, the reference is resolved to the shadowed element. For example, if a Private element shadows a base class element, code that does not have permission to access the Private element accesses the base class element instead.

    • If you shadow an element, you can still access the shadowed element through an object declared with the type of the base class. You can also access it through MyBase.

The Shadows modifier can be used in these contexts:

Class Statement

Const Statement

Declare Statement

Delegate Statement

Dim Statement

Enum Statement

Event Statement

Function Statement

Interface Statement

Property Statement

Structure Statement

Sub Statement

Consulte também

Referência

Compartilhamento (Visual Basic)

Static (Visual Basic)

Private (Visual Basic)

MustOverride (Visual Basic)

NotOverridable (Visual Basic)

Sobrecargas (Visual Basic)

Overridable (Visual Basic)

Overrides (Visual Basic)

Conceitos

Me, My, MyBase e MyClass no Visual Basic

Noções básicas de herança (Visual Basic)

Sombreamento em Visual Basic