Overrides (Visual Basic)Overrides (Visual Basic)

指定屬性或程序會覆寫繼承自基底類別的同名屬性或程序。Specifies that a property or procedure overrides an identically named property or procedure inherited from a base class.

規則Rules

  • 宣告內容。Declaration Context. 您只能在屬性或程序宣告陳述式中使用 OverridesYou can use Overrides only in a property or procedure declaration statement.

  • 結合的修飾詞。Combined Modifiers. 您不能相同的宣告中同時指定 OverridesShadowsSharedYou cannot specify Overrides together with Shadows or Shared in the same declaration. 因為覆寫項目可隱含覆寫,您無法結合 OverridableOverridesBecause an overriding element is implicitly overridable, you cannot combine Overridable with Overrides.

  • 相符簽章。Matching Signatures. 此宣告的簽章必須完全符合簽章屬性或程序,它會覆寫。The signature of this declaration must exactly match the signature of the property or procedure that it overrides. 這表示的參數清單必須有相同數目的參數、相同的順序及相同的資料類型。This means the parameter lists must have the same number of parameters, in the same order, with the same data types.

    除了簽章,覆寫宣告也必須完全符合下列各項:In addition to the signature, the overriding declaration must also exactly match the following:

    • 存取層級The access level

    • 傳回類型 (如果有的話)The return type, if any

  • 泛型簽章。Generic Signatures. 在泛型程序中,簽章包含類型參數的個數。For a generic procedure, the signature includes the number of type parameters. 因此,覆寫宣告在這方面也必須符合基底類別版本。Therefore, the overriding declaration must match the base class version in that respect as well.

  • 其他符合。Additional Matching. 除了符合簽章的基底類別版本,此宣告在下列方面也必須符合它:In addition to matching the signature of the base class version, this declaration must also match it in the following respects:

    • 存取層級修飾詞 (例如公開)Access-level modifier (such as Public)

    • 傳遞機制,每個參數 (ByVal或是ByRef)Passing mechanism of each parameter (ByVal or ByRef)

    • 泛型程序的每個類型參數的條件約束清單Constraint lists on each type parameter of a generic procedure

  • 遮蔽和覆寫。Shadowing and Overriding. 遮蔽和覆寫都會重新定義繼承的項目,但這兩種方法之間有顯著的差異。Both shadowing and overriding redefine an inherited element, but there are significant differences between the two approaches. 如需詳細資訊,請參閱 < Visual Basic 中的遮蔽功能For more information, see Shadowing in Visual Basic.

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

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

另請參閱See also