Overloads (Visual Basic)Overloads (Visual Basic)

指定屬性或程序會重新宣告一或多個同名的現有屬性或程序。Specifies that a property or procedure redeclares one or more existing properties or procedures with the same name.

備註Remarks

載是針對相同範圍內的指定屬性或程式名稱提供一個以上定義的作法。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. 您只能在屬性或程式宣告語句中使用 OverloadsYou can use Overloads only in a property or procedure declaration statement.

  • 合併的修飾詞。Combined Modifiers. 您不能在相同的程式宣告中同時指定 OverloadsShadowsYou cannot specify Overloads together with Shadows in the same procedure declaration.

  • 必要的差異。Required Differences. 宣告中的簽章必須與它多載之每個屬性或程式的簽章不同。The signature in this declaration must be different from the signature of every property or procedure that it overloads. 簽章包含屬性或程序名稱,以及下列項目: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)

    • 參數修飾詞關鍵字 (例如 ByRefOptional)parameter modifier keywords (such as ByRef or Optional)

    • 屬性或程序修飾詞關鍵字 (例如 PublicShared)property or procedure modifier keywords (such as Public or Shared)

  • 選擇性的修飾詞。Optional Modifier. 當您在同一個類別中定義多個多載屬性或程式時,不需要使用 Overloads 修飾詞。You do not have to use the Overloads modifier when you are defining multiple overloaded properties or procedures in the same class. 不過,如果您在其中一個宣告中使用 Overloads,您必須在全部的宣告中使用它。However, if you use Overloads in one of the declarations, you must use it in all of them.

  • 遮蔽和多載。Shadowing and Overloading. Overloads 也可以用來在基類中遮蔽現有的成員或一組多載成員。Overloads can also be used to shadow an existing member, or set of overloaded members, in a base class. 以此方式使用 Overloads 時,即表示您會宣告同名的屬性或方法和相同的參數清單作為基底類別成員,而且您並未提供 Shadows 關鍵字。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.

如果您使用 Overrides,編譯器會隱含地新增 Overloads,讓程式庫 API 更容易使用 C#。If you use Overrides, the compiler implicitly adds Overloads so that your library APIs work with C# more easily.

Overloads 修飾詞可用於以下內容:The Overloads modifier can be used in these contexts:

請參閱See also