Target-typed new() expressions in C# 9

User objUser = new User();
User objUser = new();
var objUser = new();//Error: There is no target type for 'new()'
var myArray = new []{1, 2, 3};
User objUser1 = new();
var objUser2 = new User();
User objUser1 = new User();
User objUSer2 = new User();
  1. Target-typed new expressions| Microsoft Docs
  2. C# 9.0: Target-typed New Expressions — Thomas Claudius Huber

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vahid Farahmandian

Vahid Farahmandian

Mainly a .Net #developer, sometimes #SQLServer admin, not yet a husband and specifically not a father. My LinkedIn: https://www.linkedin.com/in/vfarahmandian/