title: Input string was not in a correct format, List<String> to Dictionary<int, int>
body: <p>I am trying to create a program that reads user inputted integers from the console, then creates a <code>Dictionary&lt;int, int&gt;</code>, and finally prints all inputs with the number of times they have been entered.
  My idea was to collect each entry until an empty line in a List. Then I would parse it and create the dictionary with input for Key and times typed as Value.</p>
  
  <p>I get "Unhandled Exception: System.FormatException: Input string was not in a correct format" at <code>int integer = int.Parse(number);</code> and nothing gets printed.</p>
  
  <p>Would you please help me understand where the code falls apart. I am a beginner and not sure how to correct it.</p>
  
  <pre><code>static void Main(string[] args)
      {
          string input = "0";
          List&lt;string&gt; listNumbers = new List&lt;string&gt;();
          Console.WriteLine("Type several numbers and press Enter after each one:");
          while (input != string.Empty)
          {
              input = Console.ReadLine();
              listNumbers.Add(input);
          }
  
          IDictionary&lt;int, int&gt; intOccurences = new Dictionary&lt;int, int&gt;();
          foreach (string number in listNumbers)
          {
              int integer = int.Parse(number);
              int count;
              if (!intOccurences.TryGetValue(integer, out count))
              {
                  count = 0;
              }
                  intOccurences[integer] = count + 1;
          }
          PrintNumbers(intOccurences);
      }
          private static void PrintNumbers(IDictionary&lt;int, int&gt; intOccurences)
      {
          foreach (KeyValuePair&lt;int, int&gt; entry in intOccurences)
          {
              Console.WriteLine(
                  "Number '{0}' occurs {1} time (s) in the input.", entry.Key, entry.Value);
          }
      }
  </code></pre>