Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Say I have a dictionary
<br />
Dictionary<int, Dictionary<int, String>><br />

What is the best way to remove an item from the "nested" dictionary?

For e.g.:
Dictionary<int, Dictionary<int, string>> outer = new Dictionary<int, Dictionary<int, string>>();

This Dictionary is then populated with stuff and I want to remove the existing item outer[1][2], I would usually do:
Dictionary<int, string> inner = outer[1];
outer.Remove(1);
inner.Remove(2);
outer.Add(1, inner);


Is there a better/shorter/more straightforward way?
Posted

1 solution

There is no need to remove and re-add the inner dictionary when removing an item from it, so you can just do:
// To remove outer[1][2]
outer[1].Remove(2);
 
Share this answer
 
v2
Comments
la01 8-Jun-10 19:56pm    
D'oh! Never thought of that.. I think I feel the obvious blinding me :) Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900