Collectionbase with key

  • Thread starter Thread starter Kejpa
  • Start date Start date
K

Kejpa

Hi,
I've begun trying out the .NET2005 beta and one thing that I was thrilled
about in advance was the CollectionBase class. No more selfmade Collection
classes I thought.
But now I'm puzzled, I can't have a Collection class based on the
CollectionBase that accepts strings as key? It only accepts integers!
Why would I use a CollectionBase class as the base class of my collection if
it can't have a string as it's key?
Why not stick to the old way and have an internal
Collection/Hashtable/ListDictionary/WhatEver as holder for your objects ?

Should I make a suggestion to MS?

Regards
/Kejpa
 
I guessed there was a more approprite place but I couldn't find it.

Thanx for redirecting me ;)

/Kejpa
 
Kejpa,
CollectionBase has been in the framework since VS.NET 2002. It is used to
create type safe collections that are indexed by Integers.

If you want a type safe collection that are index by Strings or other object
I would recommend DictionaryBase.

Hope this helps
Jay
 
I've begun trying out the .NET2005 beta and one thing that I was thrilled
about in advance was the CollectionBase class. No more selfmade Collection

CollectionBase also exists in .Net 1.1. I haven't looked at it closely,
but is the one in .Net 2.0 any different?
Why would I use a CollectionBase class as the base class of my collection if
it can't have a string as it's key?

With the addition of generics to VB.Net, you may not need to create your
own collection classes anymore. For example, suppose you have a custom
class called MyCustomClass and you need a collection of them with a string
as a key. You can use a dictionary like this using generics:

Dim oDict As New Dictionary(Of String, MyCustomClass)

Then you can add items

Dim oCustom As New MyCustomClass
oDict.Add("Key",oCustom)

And you can access the dictionary without casting:

Dim oNewCustom As MyCustomClass = oDict("Key")

The generic collection classes available include Collection, Dictionary,
KeyedCollection, KeyValuePair, LinkedList, Queue, Stack, SortedDictionary,
and others.

I would say for the vast majority of collection needs, the built in generic
classes should fit the bill. But, you can also create you own, too! I
just hope they release it in early 2005 rather than later.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Back
Top