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?
int value = runningcount[city];
runningcount.Remove(city);
runningcount.Add(city, ++value);
and, by the way, how do I change my avatar here?
Loading

Akkiraju IvaturiPosted Aug 19, 2012, 9:59 PM
William ThompsonPosted Aug 19, 2012, 1:59 AM
Akkiraju IvaturiPosted Aug 19, 2012, 1:30 AM
if the dictionary is declared as Dictionary list = new Dictionary();
then you can set the value for the key "test" as follows
list["test"] = list["test"] + 1;
now the value for the key will get incremented by 1.
But, do let me know if you can change your avatar... Even I am facing the same challenge... :) Thanks...