title: Add & Increment the Key and Value in C# dictionary
body: <p>I'm creating a counter that counts the number of times each character occurs in a string and then prints the results to the console.</p>
  <p>Let's use this sample string:</p>
  <pre><code>string myString = &quot;The pen is mightier.&quot;
  </code></pre>
  <p>I want the results to be</p>
  <pre><code>T : 2
  h : 2
  e : 3
    : 2
  p : 1
  n : 1
  i : 3
  s : 1
  m : 1
  g : 1
  r : 1
  . : 1
  </code></pre>
  <p>I've converted the string to a character array.</p>
  <pre><code>char[] charactersInString = myString.ToCharArray();
  </code></pre>
  <p>I've created a dictionary that stores the letters and the count.</p>
  <pre><code>Dictionary&lt;char, int&gt; letters = new Dictionary&lt;char, int&gt;();
  </code></pre>
  <p>I loop through each letter in the <code>characterInString</code> array and am not sure how to initialize and add a new pair when the dictionary doesn't contain the key or how to update the value only when it does contain the key?</p>