I have the following code in c# , basically it's a simple dictionary with some keys and their values.
Dictionary<string, int> dictionary =
new Dictionary<string, int>();
dictionary.Add("cat", 2);
dictionary.Add("dog", 1);
dictionary.Add("llama", 0);
dictionary.Add("iguana", -1);
I want to update the key 'cat' with new value 5.
How could I do this?
Have you tried just
:)
Update
Beware of non-existing keys :)
Dictionary is a key value pair. Catch Key by
and assign its value like
Just use the indexer and update directly:
Try this simple function to add an dictionary item if it does not exist or update when it exists:
This is the same as dict[key] = value.