Inheriting from CollectionBase

  • Thread starter Thread starter Shayne H
  • Start date Start date
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.
 
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
 
Back
Top