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
Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
14
15
15
-
When a generic method that is part of a derived class overrides a method in the base class, you may not specify constraints on the overridden method. The override method in the derived class inherits its constraints from the method in the base class.
16
+
When a generic method that is part of a derived class overrides a method in the base class, you can't specify constraints on the overridden method. The override method in the derived class inherits its constraints from the method in the base class.
17
+
18
+
However, there are exceptions to this rule:
19
+
20
+
- Starting with C# 9, you can apply the `default` constraint to `override` and explicit interface implementation methods to resolve ambiguities with nullable reference types.
21
+
- Starting with C# 8, you can explicitly specify `where T : class` and `where T : struct` constraints on `override` and explicit interface implementation methods to allow annotations for type parameters constrained to reference types.
16
22
17
23
## Example
18
24
19
-
The following sample generates CS0460.
25
+
The following sample generates CS0460 when attempting to redeclare inherited constraints.
0 commit comments