|
-
May 12th, 2002, 07:10 PM
#1
Thread Starter
Addicted Member
newbie casting problem
I am having some trouble incrementing a value in a hashtable.
I'm new to C#.
Here's some of the things I tried to do, none of them worked.
myhashtable[mykeys[i]]++; Operator not defined
myInt32 = Int32(myhashtable[mykeys[i]]); class Int32 invalid in context.
myInt32++;
How can i cast the value in my hash table to an integer?
Thanks for any help.
That which does not kill us, only makes us stronger. 
-
May 12th, 2002, 08:07 PM
#2
Frenzied Member
there should be a ToInt32() on the hash table key or value
-
May 12th, 2002, 08:34 PM
#3
Thread Starter
Addicted Member
I was trying to get the value of the object with syntax like this
myHashtable[myKey].
The style above didn't expose a ToInt32() method only a ToString().
Do I have to use an IEnumerator interface to get to the keys or values that do expose it?
Here's what Im doing in VB .NET. I wanted to try it in C#.
wrds is a string array and htWords is a hashtable.
For i = 0 To wrds.GetUpperBound(0)
If Not htWords.ContainsKey(wrds(i)) Then
htWords.Add(wrds(i), 1)
Else
'Here is the line Im having trouble with.
htWords(wrds(i)) = CType(htWords(wrds(i)), Integer) + 1
End If
Next
Thanks for any help.
That which does not kill us, only makes us stronger. 
-
May 12th, 2002, 08:41 PM
#4
Thread Starter
Addicted Member
Oops. I meant IDictionaryEnumerator to get to the Keys and values.
That which does not kill us, only makes us stronger. 
-
May 12th, 2002, 09:08 PM
#5
Frenzied Member
-
May 12th, 2002, 09:12 PM
#6
Thread Starter
Addicted Member
Thanks! That was exactly what I was looking for.
That which does not kill us, only makes us stronger. 
-
May 13th, 2002, 12:29 AM
#7
Frenzied Member
No Problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|