Different ways of declaring arrays in VB.NET -


in vb.net, there difference between following ways of declaring arrays?

- dim cargoweights(10) double  - cargoweights = new double(10) {} 

' these 2 independent statements. not supposed execute 1 after other.

as far know, first 1 declares array variable holds value 'nothing' until array object assigned it. in other words, not initialized yet.

but second statement? "=" sign means variable being initialized , won't hold 'nothing'? going point one-dimensional array of eleven default double values (0.0)?

edit:

according msdn website:

the following example declares array variable not point array.

dim twodimstrings( , ) string

(...) variable twodimstrings has value nothing.

source: http://msdn.microsoft.com/en-us/library/18e9wyy0(v=vs.80).aspx

both dim cargoweights(10) double , cargoweights = new double(10) {} initialize array of doubles each items set default type value, in case, 0.0. (or nothing if string data type)

the difference between 2 syntax that, 2nd 1 can init value of each items in array different default value, like:

cargoweights = new double(10) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} 

to declare uninitialized array, use dim cargoweights() double or cargoweights = new double() {}.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -