Jump to content

Welcome to Obsidian Forum Community
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

How To Modify An Element in the Dictionary Class?


  • Please log in to reply
1 reply to this topic

#1
Xarzu

Xarzu

    (1) Prestidigitator

  • Members
  • 20 posts
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);

#2
Humodour

Humodour

    Arch-Mage

  • Members.
  • 3563 posts
I have no idea why you're using that horrible proprietary rip-off of Java (which I also don't have too many kind words for) when even Microsoft themselves have ditched it in favour of a return to C++, but that's just me being a language snob. But I would recommend you focus on learning Python and C++ instead. Between those two languages you've got a super powerful toolset for tackling pretty much any problem, and as an added benefit, you can embed them in each other so you can use both at once to solve a single problem. Obviously Python's strength is scripting and rapid prototyping, while C++'s strength is power, ubiquity, and performance.

Anyway the answer is yes.

runningcount[city] = runningcount[city] + 1;

BTW: the Dictionary class isn't like a hash table, it is a hash table.

Edited by Krezack, 19 August 2012 - 03:50 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users