1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Windows How To Modify An Element in the Dictionary Class?

Discussion in 'Software' started by Captain Xarzu, 19 Aug 2012.

  1. Captain Xarzu

    Captain Xarzu New Member

    Joined:
    22 Aug 2007
    Posts:
    15
    Likes Received:
    0
    How To Modify An Element in the Dictionary Class?
    =======================================

    C# has this cool Dictionary class that you can use like a Hash Table. Is there a way of changing the value of an indexed element without resorting to removing it like this?
    Code:
                   int value = runningcount[city];
                   runningcount.Remove(city);
                   runningcount.Add(city, ++value);
     
  2. Uncle Psychosis

    Uncle Psychosis Classically Trained

    Joined:
    27 Jul 2003
    Posts:
    1,694
    Likes Received:
    9
    Can't you just do:

    Code:
     runningcount[city] = ++runningcount[city] 
    ?
     
  3. Measter

    Measter New Member

    Joined:
    2 Feb 2008
    Posts:
    129
    Likes Received:
    4
    Just do this:

    Code:
    runningcount[city]++;
     
  4. jifbo

    jifbo New Member

    Joined:
    23 Sep 2012
    Posts:
    20
    Likes Received:
    1
    or even
    Pre incrementing is faster in almost all cases ;)
     

Share This Page