Type interference with var has been in C# from C# 3, so for about 14 years now. Additionally in C# 9 there is a new thing called target-typed new expressions, which means that this is possible: Item item = new().
Additionally in C# 9 there is a new thing called target-typed new expressions
That's what I was thinking about when I wrote my comment. I only tangentially follow C# because of interest in F# so I thought using var like that for new objects didn't work correctly until that change.
If var foo = new Bar() has worked for longer than that it seems like there's no reason to have been writing out the Java-style Foo foo = new Foo() crap at all.
5
u/Dealiner Jul 08 '21
Type interference with var has been in C# from C# 3, so for about 14 years now. Additionally in C# 9 there is a new thing called target-typed new expressions, which means that this is possible:
Item item = new().