title: Initializing a dictionary to custom default values
body: <p>I am trying to create a for loop that invokes a function of several instance of class <code>A</code> in a dictionary, and if there is no value for a key, it creates it and then invokes it.
  It seems to me as if there must be a way to create a value upon first access to a key.</p>
  
  <p>I am currently using this code though I think it is not the best possible practice:</p>
  
  <pre><code>(dictionary[i] = dictionary.ContainsKey(arr[i]) ? dictionary[i] : new A()).Push(10);
  </code></pre>
  
  <p>Is there a cleaner for such a problem in C#?</p>