470,862 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Inheriting from CollectionBase

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.

--
Thanks for any help,
Shayne H
Nov 20 '05 #1
2 3858
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.NameObjectCollectio nBase.

Hope this helps
Jay

"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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.

--
Thanks for any help,
Shayne H

Nov 20 '05 #2
Thanks a heap
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by m. pollack | last post: by
11 posts views Thread by Noah Coad [MVP .NET/C#] | last post: by
5 posts views Thread by Eric Johannsen | last post: by
1 post views Thread by Matthew Roberts | last post: by
3 posts views Thread by Tony Johansson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.