← Back
Milan Jovanovic December 21, 2024 41s

Is var overrated in C#? Check out Target Typed New Expressions

Summary

This C tip focuses on simplifying code by using target-typed new expressions, available since C# 9. Instead of explicitly defining the type on both the left-hand side and in the constructor for collections like dictionaries, you can now define it only once on the left. The practical takeaway is cleaner and more concise code, though using `var` in the constructor remains an alternative for older C# versions.

View original episode ↗