C# Feature - Target-typed new
Overview
Section titled βOverviewβTarget-typed new removes duplicated type names from object creation when the target type is already known.
Introduced In
Section titled βIntroduced InβC# 9.0 (2020)
Dictionary<string, int> counts = new Dictionary<string, int>();Dictionary<string, int> counts = new();Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- Use it only when the target type is obvious from context.
- Prefer explicit construction when brevity hurts readability.