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)
Before
Section titled “Before”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.