Hi,
Is it possible to change the key of a dictionary?
Thanks
Printable View
Hi,
Is it possible to change the key of a dictionary?
Thanks
What Dictionary ??? ... What Key ???
Encryption ??? What Language ????
More info needed to process....
I assume he is talking about the default Dictionary class:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
Sorry, it's the dictionary class that contains keys and values. I have a dictionary that contains a key. I anyway retrieved values of one particular key's values, added two new keys, and added the same values to the newley added keys. But when I update the value of one key, it updates the value of the other key as well. Any idea why?
Thanks
Post the code that your using, so that we can see how and why...
No, you can't rename the key of a dictionary entry directly. However, you can copy the value from the old entry to a new entry and then delete the old one. Something like this:
Code:myDictionary.Add(preferredKeyName, myDictionary(oldKeyName))
myDictionary.Remove(oldKeyName)
Never ever do that. Sorry, but my opinion is why create the dictionary in the first place then. I always have this discussion with my students. My answer is always the same. Make sure you only use what is needed. If you have to half way through your program EDIT the dictionaries, your planning is wrong. Yes, maybe there is a need for this, but in my opinion it is just edit programming ( where you keep on editing things just to keep your app going ), instead of of proper programming ( where you almost never need to edit existing objects - and your app is behaving good )
Just saying....