"barcrofter" <jd*****@gmail.comwrote in message
news:5d**********************************@a3g2000p rm.googlegroups.com...
>I have two independent arrays and mysteriously they occupy the same
space. Is this an error or a feature?
Dim tokens$() '(input list of msn's and
constants)
Dim values() As Object '(tokens with msn's replaced by
values)
temp="A = 2 * B"
'---parse the temp expression into tokens
tokens = Split(temp, " ")
'---setup a similar sized values array
ReDim values(UBound(tokens))
values=tokens
and under vb.net changing tokens(4) will now change values(4)!!.
I expected that making values = tokens would give me an array "copy by
element". In fact it made the two occupy the same array space. Is
this a bug or a language feature??
First a couple of comments:
Since you are using Dot.Net I would suggest using the new syntax so:
dim Tokens() as string
Ensure that you have options strict and explicit set to on. This will cause
you a bit of hassle at first but will pay big dividends when debugging your
app. You will then have to declare the temp variable.
As for you question you are setting a reference to an array to another array
so they will both point to the same array. What you might want to do is use
one of the Copy methods to bring the items from one array to the other.
Also if you are not looking to export this array to unmanaged code I would
suggest looking into another collection type for example a List(of T). This
will allow you to manipulate the List without having to redim all the time.
LS