What are the differences between the following constructs? Why prefer one over the other?
Number one:
Dim byteArray(20) as Byte
Number two:
Dim byteArray() as Byte = new Byte(20) {}
Any help would be appreciated.
Thank you.
Edit – I corrected some code. ‘ReDim’ should be ‘Dim’.
They both allocate 20 bytes on the managed heap.
They both set the identifier ‘byteArray’ to point to those bytes.
The statement with the ‘new’ operator (clause) allows initialization of the array elements.
Incidentally, to allocate an array with no elements specifiy a size of -1 for one of the dimensions. This is useful if you need to access properties like length without throwing an error.