Ok, I think this a little more complicated. I have two lists both
referencing the same collection of objects. The two lists simply provide
different traversal paths for the objects. For example, one may be an
alphabetic listing and the other a numeric listing. How would I load each
list (givent that each list has it's own method for sorting) without
actually instantiating multiple instances of the objects?
Dim List1 as New ArrayList()
Dim List2 as New ArrayList()
Dim A as MyObject()
Dim i as Integer
for i = 0 to 10
A = New MyObject()
List1.Add(A)
List2.Add(A)
next
In this case if I access A from one list, will the changes I make to A be
recognized by the same instance of A in the second list? Also, if I set a
reference to A in List1 to nothing, will the reference to the same
instance of A in the second list be invalid?
I guess my real question is does VB handle a reference count automatically
on instances of objects?
Herfried K. Wagner said:
You do not need to set 'A' to 'Nothing' if it is a local variable. I'd
write:
\\\
Dim AList As New ArrayList()
For i As Integer = 0 To 10
AList.Add(New MyObject())
Next i
///
Scott, think of it this way. You create the object once. At that point it
most likely is "resident" in a variable. Now you can add it to as many
collections as you wish. You could later on find an object in a collection
and then add it to another. Since each collection has its own sorting each
list can show the objects in a specific order.
The other good thing -- update the object once. Now if you update info you
should know where it is shown since changing a field may change the display
characteristics of that object.
Lloyd Sheen