James T. wrote:
Now, I would like to add each item an ID property, so I could access
items in the collection by ID. What I need is a sample how I can
generate unique ID each time when a new Item is added to the
collection?
The way I approached this is to use actual values from within the collected
objects to provide IDs.
If I'm collecting users, I'll use the username as the identifier. This has
to be unique as each user has a unique username.
I then get my Item property to scan through the collection looking for the
user with the supplied username. If it finds it then the user is returned,
if no user is located then Nothing is returned. This also gives me a really
easy 'Exists' type function, because if Item returns Nothing then the item
doesn't exist within the collection.
It also has the advantage of dynamically updating the item keys if the
properties of the objects change. If I modify an object's Username property,
the Item key will automatically be updated with it (as they are both the
same value).
This may or may not be practical depending on what type of object you are
collecting, but worth thinking about.
--
(O)enone