Collections

bpayne111

Junior Contributor
Joined
Feb 28, 2003
Messages
325
Location
BFE
I have two sets of collection objects (inherit from collection base) in a project. A property in collection A, depends on the index of an object in collection B.
Everything is great until items are removed from collection B because the indexes are changed and the property that depends on the index in collection B is now wrong.
I can fix this programmatically many different ways. But i wonder if maybe there is a collection defined in .NET that would be of use to fixing this problem. I am not searching these collections just constantly updating properties, in loops.


My best idea so far was to create an array named TrueIndex that holds the values of the real indexes an allows me to trick my program in a sense. I was considering a loop but i have graphics that depend on this and the loop would slow down everything considerably.

any ideas?
 
Why would you make a property dependant on the index of something in a collection? Why not just make it dependant on the something itself?

You can use the collection's IndexOf function to get the index of the something in the collection whenever you like.
 
The best way is to probably just go into System.Collection or System.Collections.Specialized namespaces with the object browser and take a look at the different collections. That way you can look at all their functionalities and the way they work, and determine which one will best fit your current project.

I'm not sure what Collection you're using (ArrayList?), but instead of removing the object perhaps you could set that location to null (c#) or nothing (vb).

Not really sure how you have things set up, so just giving ideas off the top of my head here. :)
 
Try looking under mscorlib for System.Collections

mscorlib -> System.Collections
in the object browser.
 
well i thought about using 'nothing' but i kind of like the fact that my objects get smaller as they go... this makes the program run much faster in the long term (consider a chess engine that uses these values over and over)
i've done reading on them but didn't see specialized collections
i will look at specialized collections maybe that's my missing link
thanks for the info
 
Back
Top