Custom Collections

  • Thread starter Thread starter James T.
  • Start date Start date
J

James T.

Hello!

I defined a custom collection class that inherits from CollectionBase, it
works fine...

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?

Thanks!

James
 
How about running a int TotalItemAdded private field?

private int TotalItemsAdded

public Add( object o )
{
o.ID = "item_" + TotalItemsAdded.ToString();
//Add item
TotalItemsAdded++;
}

Note that nothing decrements TotalItemsAdded.

bill
 
Hello!

I defined a custom collection class that inherits from CollectionBase, it
works fine...

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?

Guid guidID = Guid.NewGuid();

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top