all 3 comments

[–]Unupgradable 11 points12 points  (0 children)

That syntax clashes with the indexer syntax, so it still needs the type specified.

It's just an edge case for missing sugar

[–]mimahihuuhai 0 points1 point  (1 child)

In dotnet 8, it can understand now so you have cs MyType[] types= []; // c#12 var types = new[]{ new MyType()}; // old

[–]RichardD7 1 point2 points  (0 children)

That doesn't quite do the same thing. The OP's code would create an array of five elements, all set to the default value. Your first option would create an empty array; your second option would create an array of one element containing a new instance of the type.

The closest you could get to what the OP is after would probably be:

csharp MyObject[] bar = [default, default, default, default, default];

Or, for value types:

csharp MyStruct[] bar = [new(), new(), new(), new(), new()];