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. Overrides只能在属性或过程声明语句中使用。You can use Overrides only in a property or procedure declaration statement.

  • 组合修饰符。Combined Modifiers. 不能在 Overrides Shadows 同一声明中同时指定和或 SharedYou cannot specify Overrides together with Shadows or Shared in the same declaration. 由于重写元素是隐式可重写的,因此不能将 OverridableOverrides 组合到一起。Because 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:

    • 访问级别修饰符(如PublicAccess-level modifier (such as Public)

    • 传递每个参数的机制(ByValByRefPassing 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