title: Can I initialize Dictionary Values automatically?
body: <p>Let's say I want to store my data as a bunch of named lists.</p>
  
  <p>I really like how with <code>Dictionary</code>, you can do:</p>
  
  <pre><code>myDictionary["SomeKey"] = new List&lt;string&gt;{ "SomeString" };
  </code></pre>
  
  <p>But unfortunately, I cannot safely do:</p>
  
  <pre><code>myDictionary["SomeKey"].Add("SomeString");
  </code></pre>
  
  <p>Because if the <code>List</code> at <code>SomeKey</code> has not yet been initialized, I'll get a null reference exception.</p>
  
  <p>So everytime I alter a value in the dictionary, I have to do:</p>
  
  <pre><code>if (!myDictionary.ContainsKey("SomeKey")) myDictionary["SomeKey"] = new List&lt;string&gt;();
  </code></pre>
  
  <p>Before I can safely add to each list. It looks ugly and distracts from non-boilerplate code. I also duplicate code in several places (accessing <code>SomeKey</code> several times when all I want to say is "add this element to the list at <code>SomeKey</code>, regardless of whether it is empty or not").</p>
  
  <p>There is basically no reason why I would want uninitialized values in my <code>Dictionary</code>. If it was an array of <code>List</code>, I would have looped through every element beforehand and initialized each member; I can't do this with <code>Dictionary</code> because I don't know what the keys will be in advance.</p>
  
  <p>Is there a more concise syntax for saying, "access the value at this key, and if it is null, then initialize it"?</p>