title: Nested Dictionary collection in .NET
body: <p>The .NET <code>Dictionary&lt;TKey, TValue&gt;</code> object allows assignment of key/values like so:</p>
  
  <pre><code>Dictionary&lt;string, string&gt; dict = new Dictionary&lt;string, string&gt;();
  dict["1"] = "foo";
  dict["2"] = "bar";
  </code></pre>
  
  <p>but I cannot use a Dictionary like so:</p>
  
  <pre><code>Dictionary&lt;string, string&gt; dict = new Dictionary&lt;string, string&gt;();
  dict["F1"]["F2"]["F3"] = "foo";
  dict["2"]["X"] = "bar";
  </code></pre>
  
  <p>Is there a collection in .NET which allows me to nest <code>[]</code>, or would I have to create my own?</p>
  
  <p>If I have to create my own, how would I do this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It would also be useful if I could have implementations which expect unique keys, like so:</p>
  
  <pre><code>dict["F1"]["F2"]["F3"] = "foo";
  dict["F1"]["F2"]["F3"] = "bar"; //result is "bar" because "foo" was overridden
  </code></pre>
  
  <p>and an implementation where a key can be used more than once</p>
  
  <pre><code>dict["F1"]["F2"]["F3"] = "foo";
  dict["F1"]["F2"]["F3"] = "bar"; //result can be "foo" and "bar"
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p><strong>EDIT (as per Jon Skeet's question):</strong></p>
  
  <p>I want to use the structure like so (as a very rough example):</p>
  
  <pre><code>json["data"]["request"]["name"] = "username";
  json["data"]["request"]["pass"] = "password";
  </code></pre>
  
  <p>resolves to</p>
  
  <pre><code>{ data: { request: { name: "username", pass: "password" } } }
  </code></pre>
  
  <p>and equally there would be an equivalent for XML etc.</p>