Results 1 to 7 of 7

Thread: newbie casting problem

  1. #1

    Thread Starter
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169

    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.

  2. #2

  3. #3

    Thread Starter
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    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.

  4. #4

    Thread Starter
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Oops. I meant IDictionaryEnumerator to get to the Keys and values.
    That which does not kill us, only makes us stronger.

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try Convert.ToInt32();

  6. #6

    Thread Starter
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Thanks! That was exactly what I was looking for.
    That which does not kill us, only makes us stronger.

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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
  •  



Click Here to Expand Forum to Full Width