-
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.
:)
-
there should be a ToInt32() on the hash table key or value
-
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.
-
Oops. I meant IDictionaryEnumerator to get to the Keys and values. :D
-
-
Thanks! That was exactly what I was looking for. :)
-