Home All Groups Group Topic Archive Search About

Strict type for Hashtable?

Author
13 Jul 2006 11:45 PM
Shane
I thought that arrays and hash tables could be strictly typed under 2.0
instead of just being objects, but I can't find any documentation.

I want to have the values in a hash table designated as a string type,
so that I don't have to keep doing  something like:

strSomething = CStr(hashtable(Key))

I'd rather have
strSomething = hashtable(Key)

Do the hashtables support this? If they do, what is the syntax?

Thanks,
Shane

Author
14 Jul 2006 2:19 AM
GhostInAK
Hello Shane,

Check out the System.Collections.Generic namespace and look up the documentation
on the new "Of" keyword.

-Boo

Show quoteHide quote
> I thought that arrays and hash tables could be strictly typed under
> 2.0 instead of just being objects, but I can't find any documentation.
>
> I want to have the values in a hash table designated as a string type,
> so that I don't have to keep doing  something like:
>
> strSomething = CStr(hashtable(Key))
>
> I'd rather have
> strSomething = hashtable(Key)
> Do the hashtables support this? If they do, what is the syntax?
>
> Thanks,
> Shane
Author
14 Jul 2006 5:21 AM
David Anton
Yes, but the generic hashtable is the Dictionary(Of T) in the
System.Collections.Generic namespace.
e.g.,
Dim GenericHashtable As New Dictionary(Of String)
GenericHashtable.Add(somekey, somestring)
Dim thisString = GenericHashtable(somekey)

(also, List(Of T) is the generic replacement for ArrayList in 2.0)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#


Show quoteHide quote
"Shane" wrote:

> I thought that arrays and hash tables could be strictly typed under 2.0
> instead of just being objects, but I can't find any documentation.
>
> I want to have the values in a hash table designated as a string type,
> so that I don't have to keep doing  something like:
>
> strSomething = CStr(hashtable(Key))
>
> I'd rather have
> strSomething = hashtable(Key)
>
> Do the hashtables support this? If they do, what is the syntax?
>
> Thanks,
> Shane
>
>