Skip to content

[Proposal]: Target-typed generic type inference #9626

@MadsTorgersen

Description

@MadsTorgersen

Target-typed generic type inference

Summary

Generic type inference may take a target type into account. For instance, given:

public class MyCollection
{
    public static MyCollection<T> Create<T>() { ... }
}
public class MyCollection<T> : IEnumerable<T> { ... }

We would allow the Create method to be called without type argument when it can be inferred from a target type:

IEnumerable<string> c = MyCollection.Create(); // 'T' = 'string' inferred from target type

Design meetings

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions