471,337 Members | 888 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Using hashing in collectionbase

Hi all,

I am having class which is derived from collectionbase class.

I am adding some string elements to this collection.

What i want is to add support of hashing into class which i have
derived from collectionbase.

Because currently i am adding strings to my collection and at a time of
removing it is allowing me to removing only according to index and i
want to add functionality of removing through particular key which
should be unique.

Does any one have any idea about this.

Any help will be truely appreciated.

Thanks in advance.

Jan 9 '06 #1
3 1478
My answer would be not to re-invent the wheel; rather than deriving from
CollectionBase, I tend to use encapsulation, i.e. I would have an
instance-field which holds either a Dictionary<string,string> (2.0 onwards)
or a NameValueCollection, which I would then expose through whichever
interfaces and indexers I choose.

If you really want to inherit, neither of these is sealed - but I'd struggle
to see much of a reason (without more info). You might even find that
Dictionary<string,string> or NameValueCollection are enough for your needs
without writing your own class.

Any use?

Marc

"myPosts" <tr**************@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi all,

I am having class which is derived from collectionbase class.

I am adding some string elements to this collection.

What i want is to add support of hashing into class which i have
derived from collectionbase.

Because currently i am adding strings to my collection and at a time of
removing it is allowing me to removing only according to index and i
want to add functionality of removing through particular key which
should be unique.

Does any one have any idea about this.

Any help will be truely appreciated.

Thanks in advance.

Jan 9 '06 #2
Hi,

Because currently i am adding strings to my collection and at a time of
removing it is allowing me to removing only according to index and i
want to add functionality of removing through particular key which
should be unique.


How do you associate this key to the string?

You can use any kind of internal storage inside your collection, by default
CollectionBase use an ArrayList , but you can change it as you need.
In your case I would use a HashTable.
Just note that if you do so you will lose the indexing capabilities as a
Hashtable do not assure it.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 9 '06 #3
You really don't want a CollectionBase here. What you want to use is a
DictionaryBase, which is used for a map (key/value). A collection is
indexed, and not appropriate here.

Of course, in .NET 2.0, you would use the Dictionary class, and not have
to worry about this.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"myPosts" <tr**************@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi all,

I am having class which is derived from collectionbase class.

I am adding some string elements to this collection.

What i want is to add support of hashing into class which i have
derived from collectionbase.

Because currently i am adding strings to my collection and at a time of
removing it is allowing me to removing only according to index and i
want to add functionality of removing through particular key which
should be unique.

Does any one have any idea about this.

Any help will be truely appreciated.

Thanks in advance.

Jan 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Clint Olsen | last post: by
5 posts views Thread by Eric Johannsen | last post: by
11 posts views Thread by Wm. Scott Miller | last post: by
1 post views Thread by Tinku | last post: by
3 posts views Thread by Tony | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.