James Bagnall James Bagnall - 11 months ago 55
Vb.net Question

Use of empty curly brackets in 2D array

Having some trouble trying to figure out the use of the empty curly brackets for the 2D array 'Landscape'.

The Declaration of 'Landscape' is the second line in the picture and the use of the curly brackets are 3 lines up from the bottom of the image.

It would be great if someone could tell me what the empty curly brackets are used for :) Thank you!

Note: LandscapeSize is an Integer and Location is a Class

The Code

Answer Source

There's no official documentation about them as far as I know, but they're used together with New Location(LandscapeSize, LandscapeSize) to instantiate your Landscape variable as an empty array of Location objects.

If you would not use the brackets the compiler would think you're trying to instantiate a single Location object, passing LandscapeSize, LandscapeSize to the constructor.

Otherwise the brackets are used to fill the array:

Landscape = New Location(LandscapeSize, LandscapeSize) {New Location, New Location, ...}