469,362 Members | 2,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Hashtable's Key Datatype

48
Hi there,

Please see the below code to understand my problem:

Dim ht As Hashtable = New Hashtable
With ht
For indx As Short = 3 To 6
.Add(indx, 3.1113213132)
Next
End With

Now when I try to retrieve the value for a particular key (say for example: ht(5)), I get the value as "Nothing" but on the other hand if I change the datatype of the variable indx to Int32, it works absolutely fine.

So my question is whether or not the hashtable support a key of type Short (Int16 in .NET Framework)?

Regards,
Aads
Nov 28 '08 #1
2 2452
nukefusion
221 Expert 100+
My guess is that when you write ht(5), the compiler interprets the 5 as an Integer (Int32) and that is why it fails, as your keys are of type Int16.

Take the following code for example. The first attempt to get the value will fail, the second will succeed.

Expand|Select|Wrap|Line Numbers
  1.   Dim ht As Hashtable = New Hashtable
  2.         With ht
  3.             For indx As Short = 3 To 6
  4.                 .Add(indx, 3.1113213132)
  5.             Next
  6.         End With
  7.         Dim o As Object
  8.  
  9.         ' This attempt will fail
  10.         o = ht(5)
  11.  
  12.         ' This attempt succeeds
  13.         Dim s As Short = 5
  14.         o = ht(s)
  15.  
Nov 28 '08 #2
Aads
48
Hi,

Many thanks for letting me know the reason! I appreciate it.


Cheers,
Aads
Dec 6 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by A.M | last post: by
5 posts views Thread by francois | last post: by
33 posts views Thread by Ken | last post: by
16 posts views Thread by Sreekanth | last post: by
1 post views Thread by Netmonster | last post: by
3 posts views Thread by Fred | last post: by
7 posts views Thread by J L | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.