List anomoly - feature or bug

jpvniekerk

Active Member
Licensed User
Longtime User
I just found out (the hard way) that if you have 2 lists and somewhere in your program you set

Code:
ListB = ListA ' save old values for later retrieval
ListA.Clear

And later
Code:
ListA = ListB ' Retrieve old values
... List A was empty

This was a bit unexpected

I overcame this with
Code:
ListB.Clear
For i = 0 to ListA.Size - 1
    ListB.Add(ListA.Get(i))
Next
ListA.clear

Then later to restore
Code:
ListA.Clear
For i = 0 to ListA.Size - 1
    ListA.Add(ListB.Get(i))
Next
ListB.clear

Is it supposed to maintain the equal relationship between the two lists if it is set to equal somewhere in the program, or is it a bug? - No other variables maintain this "automatic" equal relationship.
 
That is how it is mean to be.
When you do ListB = ListA, it does not copy the whole list into ListB, but now ListB just references ListA. Only primitive types (like int etc) are copied by value.
In order to copy the list, you will have to do it manually, iterating over all the entries.
 
Upvote 0
Back
Top