Skip to content

Partial Classes and Methods programming guide contradicts C# spec about generic constraints #26542

Closed
@Sweeper777

Description

@Sweeper777

On the "Partial Classes and Methods - C# Programming Guide" page, it is said that:

Partial methods can be generic. Constraints are put on the defining partial method declaration, and may optionally be repeated on the implementing one.

This is contradictory to what the C# language specification says (and also to the actual behaviour of dotnet), which is:

Corresponding type parameters in the declarations must have the same constraints (modulo differences in type parameter names).

Generic constraints must be repeated on the implementing declaration, not "optionally", as this code does not compile:

public partial class C {
    public partial void M<T>() where T: class;
}

public partial class C {
    public partial void M<T>() {
        
    }
}

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 229457

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-csharp/svcfundamentals/subsvcin-prThis issue will be closed (fixed) by an active pull request.okr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions