Compartilhar via


Sobrecargas (Visual Basic)

Specifies that a property or procedure redeclares one or more existing properties or procedures with the same name.

Comentários

Overloading is the practice of supplying more than one definition for a given property or procedure name in the same scope. Redeclaring a property or procedure with a different signature is sometimes called hiding by signature.

Rules

  • Declaration Context. You can use Overloads only in a property or procedure declaration statement.

  • Combined Modifiers. Não é possível especificar Overloads em conjunto com Shadows (Visual Basic) em que a mesmadeclaraçãode procedimento.

  • Required Differences. O assinatura nessa declaração deve ser diferente da assinatura de cada propriedade ou um procedimento que sobrecarrega. The signature comprises the property or procedure name together with the following:

    • the number of parameters

    • the order of the parameters

    • the data types of the parameters

    • the number of type parameters (for a generic procedure)

    • the return type (only for a conversion operator procedure)

    All overloads must have the same name, but each must differ from all the others in one or more of the preceding respects. This allows the compiler to distinguish which version to use when code calls the property or procedure.

  • Disallowed Differences. Changing one or more of the following is not valid for overloading a property or procedure, because they are not part of the signature:

    • whether or not it returns a value (for a procedure)

    • the data type of the return value (except for a conversion operator)

    • the names of the parameters or type parameters

    • the constraints on the type parameters (for a generic procedure)

    • parameter modifier keywords (such as ByRef or Optional)

    • property or procedure modifier keywords (such as Public or Shared)

  • Optional Modifier. Você não precisará usar o Overloads modificador quando você está definindo várias propriedades sobrecarregadas ou procedimentos na mesma classe. However, if you use Overloads in one of the declarations, you must use it in all of them.

  • Shadowing and Overloading. Overloads can also be used to shadow an existing member, or set of overloaded members, in a base class. When you use Overloads in this way, you declare the property or method with the same name and the same parameter list as the base class member, and you do not supply the Shadows keyword.

The Overloads modifier can be used in these contexts:

Function Statement

Instrução Operator

Property Statement

Sub Statement

Consulte também

Tarefas

Como: Definir um operador de conversão (Visual Basic)

Referência

Shadows (Visual Basic)

Conceitos

Sobrecarga de procedimento (Visual Basic)

Tipos genéricos no Visual Basic (Visual Basic)

Procedimentos de operador (Visual Basic)