C#9 was officially announced a couple days ago. One new language features is "target-typed new expressions", which feel pretty similar in usage to var
. Comparing the following declarations, I'm curious which is more performant, if any, and which syntax should be preferred for different contexts.
var person = new Person()
vs Person person = new()
.
And for collections:
var people = new[] {
new Person(),
new Person(),
new Person(),
}
vs
var people = new Person[] {
new(),
new(),
new(),
}
var
was comparing it to explicitly-typed declarations, or requesting that it be allowed on member declarations. This C#9 syntax is quite new, so I figured I'd ask the question. I also don't know everything about how compilers work, so I didnt know if it had runtime implications – Trimble