You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: standard/classes.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2746,6 +2746,8 @@ When an instance method declaration includes an `override` modifier, the method
2746
2746
2747
2747
Themethodoverriddenbyanoverridedeclarationisknownasthe ***overriddenbasemethod*** Foranoverridemethod `M` declaredinaclass `C`, theoverriddenbasemethodisdeterminedbyexaminingeachbaseclassof `C`, startingwiththedirectbaseclassof `C` and continuing with each successive direct base class, until in a given base class type at least one accessible method is located which has the same signature as `M` after substitution of type arguments. For the purposes of locating the overridden base method, a method is considered accessible if it is `public`, if it is `protected`, if it is `protected internal`, or if it is either `internal` or `private protected` and declared in the same program as `C`.
2748
2748
2749
+
For an override method `M` declared in an interface `I`, the overridden base method is determined by examining each direct or indirect base interface of `I`, collecting the set of interfaces declaring an accessible method which has the same signature as `M` after substitution of type arguments. If this set of interfaces has a *most derived type*, to which there is an identity or implicit reference conversion from every type in this set, and that type contains a unique such method declaration, then that is the overridden base method.
2750
+
2749
2751
The overriding method inherits any *type_parameter_constraints_clause*s of the overridden base method.
2750
2752
2751
2753
A compile-time error occurs unless all of the following are true for an override declaration:
@@ -2754,8 +2756,11 @@ A compile-time error occurs unless all of the following are true for an override
2754
2756
- Thereisexactlyonesuchoverriddenbasemethod. Thisrestrictionhaseffectonlyifthebaseclasstypeisaconstructedtype where the substitution of type arguments makes the signature of two methods the same.
2755
2757
- The overridden base method is a virtual, abstract, or override method. In other words, the overridden base method cannot be static or non-virtual.
2756
2758
- The overridden base method is not a sealed method.
2757
-
- There is an identity conversion between the return type of the overridden base method and the override method.
2759
+
- The override method has a return type that is convertible by an identity conversion or (ifthemethodhasavalue return) an implicit reference conversion to the return type of the overridden base method.
2760
+
- The override method has a return type that is convertible by an identity conversion or (ifthemethodhasavaluereturna) an implicit reference conversion to the return type of every override of the overridden base method that is declared in a (director indirect) base type of the override method.
2758
2761
- The override declaration and the overridden base method have the same declared accessibility. In other words, an override declaration cannot change the accessibility of the virtual method. However, if the overridden base method is protected internal and it is declared in a different assembly than the assembly containing the override declaration then the override declaration’s declared accessibility shall be protected.
2762
+
- The override method's return type is at least as accessible as the override method.
- A *type_parameter_constraints_clause* mayonlyconsistofthe `class` or `struct` *primary_constraint*sappliedto *type_parameter*swhichareknownaccordingtotheinheritedconstraintstobeeitherreferenceorvaluetypesrespectively. Anytypeoftheform `T?` intheoverridingmethod’ssignature, where `T` is a type parameter, is interpreted as follows:
2760
2765
- Ifa `class` constraintisaddedfortypeparameter `T` then `T?` isanullablereferencetype; otherwise
2761
2766
-Ifeitherthereisnoaddedconstraint, ora `struct` constraint is added, for the type parameter `T` then `T?` is a nullable value type.
@@ -3939,7 +3944,7 @@ A property declaration that includes both the `abstract` and `override` modifier
3939
3944
3940
3945
Abstract property declarations are only permitted in abstract classes ([§15.2.2.2](classes.md#15222-abstract-classes)) andinterfaces ([§19.4.4](interfaces.md#1944-interface-properties)). Theaccessorsofaninheritedvirtualpropertycanbeoverriddeninaderivedclassby including a property declaration that specifies an `override` directive. This is known as an ***overriding property declaration***. An overriding property declaration does not declare a new property. Instead, it simply specializes the implementations of the accessors of an existing virtual property.
3941
3946
3942
-
The override declaration and the overridden base property are required to have the same declared accessibility. In other words, an override declaration shall not change the accessibility of the base property. However, if the overridden base property is protected internal and it is declared in a different assembly than the assembly containing the override declaration then the override declaration’s declared accessibility shall be protected. If the inherited property has only a single accessor (i.e., iftheinheritedpropertyisread-onlyor write-only), the overriding property shall include only that accessor. If the inherited property includes both accessors (i.e., iftheinheritedpropertyisread-write), the overriding property can include either a single accessor or both accessors. There shall be an identity conversion between the type of the overriding and the inherited property.
3947
+
The override declaration and the overridden base property are required to have the same declared accessibility. In other words, an override declaration shall not change the accessibility of the base property. However, if the overridden base property is protected internal and it is declared in a different assembly than the assembly containing the override declaration then the override declaration’s declared accessibility shall be protected. The overriding property's type shall be at least as accessible as the overriding property. If the inherited property has only a single accessor (i.e., if the inherited property is read-only or write-only), the overriding property shall include only that accessor. If the inherited property includes both accessors (i.e., if the inherited property is read-write), the overriding property can include either a single accessor or both accessors. There shall be an identity conversion or (if the inherited property is read-only and has a value return) an implicit reference conversion between the type of the overriding and the inherited property.
3943
3948
3944
3949
An overriding property declaration may include the `sealed` modifier. Use of this modifier prevents a derived class from further overriding the property. The accessors of a sealed property are also sealed.
0 commit comments