-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
Target-typed generic type inference
- Specification: https://github.com/dotnet/csharplang/blob/main/proposals/target-typed-generic-type-inference.md
- Discussion: {Discussion]: Target-typed generic type inference #9628
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