title: Adding to a Dictionary within a dictionary
body: <p>I am not a particularly confident programmer yet but am getting there. </p>
  
  <p>My problem is that I have a</p>
  
  <pre><code>    static Dictionary&lt;string, Dictionary&lt;string, List&lt;string&gt;&gt;&gt; testDictionary = ...
  </code></pre>
  
  <p>If the Dictionary doesn't contain the current key (string), I can easily add the key and another dictionary that has been populated, like so...</p>
  
  <pre><code>   testDictionary.Add(userAgentResult, allowDisallowDictionary);
  </code></pre>
  
  <p>That works fine, my problem comes when I am trying to add the inner dictionary if the userAgentResult Key already exists. </p>
  
  <p>I was hoping to do it this way...</p>
  
  <pre><code>    testDictionary[userAgentResult].Add(allowDisallowDictionary);
  </code></pre>
  
  <p>but the .Add method wants two arguments, i.e. the string key and list value. So I went on to write this code...</p>
  
  <pre><code>    //this list as the dictionary requires a list
      List&lt;string&gt; testDictionaryList = new List&lt;string&gt;();
      //this method returns a string
      testDictionaryList.Add(regexForm(allowResult, url));
      //this will add the key and value to the inner dictionary, the value, and then     
      //add this value at the userAgentKey
      testDictionary[userAgentResult].Add(allowDisallowKey, testDictionaryList);
  </code></pre>
  
  <p>This also works, my problem is that this dictionary is added to numerous times, and when the inner dictionary already contains the key that is trying to be added, it obviously errors. So when </p>