title: C# easy way to add keys and values to nested dictionary?
body: <p>Is there an easy way to add value to a nested dictionary. I am looking for a way to replace the following type of code with an easy one.</p>
  
  <pre><code>if (NestedDictionary.ContainsKey(key1))
  {
      if (NestedDictionary[key1].ContainsKey(key2))
      {
          if (NestedDictionary[key1][key2].ContainsKey(key3))
          {   
              //do nothing
          }
          else
          {
              NestedDictionary[key1][key2].Add(key3,1);
  
          }
      }
      else
      {
  
          NestedDictionary[key1].Add(key2, new Dictionary&lt;int,int&gt;() { { key3, 1 } });
      }
  }
  else
  {
      NestedDictionary.Add(key1, new Dictionary&lt;int, Dictionary&lt;int,int&gt;&gt;() { { key2, new Dictionary&lt;int,int&gt;() { { key3, 1} } } });
  }
  </code></pre>