[Proposal]: Target-typed generic type inference
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.1k
- Avg merge
- 11h 1m
- Merged PRs (30d)
- 3
Description
# Target-typed generic type inference
* Specification: https://github.com/dotnet/csharplang/blob/main/proposals/target-typed-generic-type-inference.md
* Discussion: https://github.com/dotnet/csharplang/discussions/9628
## Summary
[summary]: #summary
Generic type inference may take a target type into account. For instance, given:
```csharp
public class MyCollection
{
public static MyCollection Create() { ... }
}
public class MyCollection : IEnumerable { ... }
```
We would allow the `Create` method to be called without type argument when it can be inferred from a target type:
```csharp
IEnumerable c = MyCollection.Create(); // 'T' = 'string' inferred from target type
```
## Design meetings
* https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-08-18.md#type-inference
* https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-08-20.md#target-type-inference-improvements
* https://github.com/dotnet/csharplang/blob/main/meetings/2026/LDM-2026-08-19.md#type-parameter-inference-for-constructor-calls
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.