Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 1, 2025

Summary

Fixes #43518

The documentation contained a false statement claiming that generic interfaces can only inherit from non-generic interfaces if the generic interface is covariant. This is incorrect—any generic interface can inherit from a non-generic interface regardless of variance.

What Was Wrong

The original text stated:

Generic interfaces can inherit from non-generic interfaces if the generic interface is covariant, which means it only uses its type parameter as a return value.

This is demonstrably false. Generic interfaces can inherit from non-generic interfaces whether they are covariant, contravariant, or invariant. The inheritance has no variance requirement.

What Changed

The corrected text now:

  1. Removes the false conditional: States that generic interfaces CAN inherit from non-generic interfaces (no covariance requirement)
  2. Explains the actual mechanism: When a generic interface inherits from a non-generic interface, the type parameter replaces object in the overridden members
  3. Clarifies the IEnumerable example: Shows how T replaces object specifically in output positions (return types and property getters)
  4. Explains why covariance is possible: Because T is used only in output positions in IEnumerable<T>, it can be marked as covariant
  5. Addresses the contrapositive: Notes that if T were used in an input position in an overridden member, the interface couldn't be covariant, and the compiler would generate an error

This correction incorporates the clarification provided by @BillWagner about how type parameters replace object in overridden members.

Verification

  • Markdown linting passes with no errors
  • Created test programs demonstrating that covariant, contravariant, and invariant generic interfaces can all inherit from non-generic interfaces
  • Only one line changed (minimal modification)

Co-authored-by: BillWagner [email protected]

Original prompt

This section details on the original issue you should resolve

<issue_title>Completely false statement about generic interface inheriting from non-generic interface</issue_title>
<issue_description>### Type of issue

Other (describe below)

Description

The page contains the false statement

Generic interfaces can inherit from non-generic interfaces if the generic interface is covariant, which means it only uses its type parameter as a return value. In the .NET class library, IEnumerable<T> inherits from IEnumerable because IEnumerable<T> only uses T in the return value of GetEnumerator and in the Current property getter.

Not sure if and what got lost in translation/editing there with these two sentences, but it is obviously entirely false from the beginning to end.

Generic interfaces can inherit non-generic interfaces regardless of variance. And IEnumerable<T> being covariant is not because it inherits IEnumerable or vice versa.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-interfaces

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/programming-guide/generics/generic-interfaces.md

Document Version Independent Id

d54ecf19-fccb-3d6b-d990-81529acf44c3

Platform Id

bf75a432-ec19-5df7-3485-3b75577d31e8

Article author

@BillWagner

Metadata

  • ID: be0a00a9-fd5d-3aae-9788-d6b324f17599
  • PlatformId: bf75a432-ec19-5df7-3485-3b75577d31e8
  • Service: dotnet-csharp
  • Sub-service: fundamentals

Related Issues</issue_description>

Comments on the Issue (you are @copilot in this section)

@BillWagner This could use clarification: The important details for `IEnumerable` and `IEnumerable` are that the type parameter, `T` replaces `object` in some overriden members. The members where `T` replaces `object` are all covariant. If `T` were to replace `object` in an input location in an overridden member, that would be a compiler error.
Fixes #47104

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/csharp/programming-guide/generics/generic-interfaces.md Generic Interfaces (C# Programming Guide)

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Oct 1, 2025
The previous statement incorrectly claimed that generic interfaces can only inherit from non-generic interfaces if they are covariant. This is false - any generic interface can inherit from a non-generic interface regardless of variance.

The corrected text now:
1. States correctly that generic interfaces CAN inherit from non-generic interfaces (no conditions)
2. Explains that when this happens, the type parameter replaces 'object' in overridden members
3. Uses IEnumerable<T> as an example where T replaces object in output positions
4. Clarifies that because T is used only in output positions, the interface CAN be marked as covariant
5. Notes that if T were used in input positions, it couldn't be covariant

This addresses the issue raised in #43518 and incorporates Bill Wagner's clarification.

Co-authored-by: BillWagner <[email protected]>
@Copilot Copilot AI changed the title [WIP] Completely false statement about generic interface inheriting from non-generic interface Fix incorrect statement about generic interface inheritance requiring covariance Oct 1, 2025
@Copilot Copilot AI requested a review from BillWagner October 1, 2025 15:39
Copilot finished work on behalf of BillWagner October 1, 2025 15:39
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, with one suggestion.

@BillWagner BillWagner marked this pull request as ready for review October 2, 2025 12:49
@BillWagner BillWagner requested a review from a team as a code owner October 2, 2025 12:49
@BillWagner BillWagner requested a review from IEvangelist October 2, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc fundamentals/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completely false statement about generic interface inheriting from non-generic interface
2 participants