Inheriting from CollectionBase

S

Shayne H

I wanted to create a type-safe collection by inheriting from CollectionBase.

Public Class MyCollection : Inherits CollectionBase

I found that IList.Add did not allow the setting of a "key" to identify an
object added to the collection.
So to implement a "key" similar to the parameter allowed by the standard
Collection object do I have to create my own array to store the "keys" and
manage it within my class MyCollection? I can't see how I will be able to
make sure my array of "keys" will always point to the correct items in the
collection.
Seems a headache, would like to know if there is some other class I can
inherit from to gain methods more similar to that of Collection.
 
J

Jay B. Harlow [MVP - Outlook]

Shayne,
If you want to store elements by key, you should inherit from
DictionaryBase.

If you want to index elements by both key & integer, then I would suggest
inheriting from System.Collections.Specialized.NameObjectCollectionBase.

Hope this helps
Jay
 

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

Top