title: How to fix 'Value cannot be null. Parameter name: Key' error in c#
body: <p>I was using Dictionary in C# and wanted to display a Key inputted by the user and display that key and its corresponding value if that key is present in the dictionary. Also, continue reading the lines until there is no more input.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  
  class Solution 
  {
      static void Main(String[] args) 
      {
          string number = Console.ReadLine();
          int n;
          Int32.TryParse(number, out n);
  
          var phoneBook = new Dictionary&lt;string, string&gt;();
  
          for(int i = 0; i &lt; n; i++)
          {
              string name = Console.ReadLine();
              string phoneNumber = Console.ReadLine();
              phoneBook.Add(name, phoneNumber);
          }
  
          foreach (var pair in phoneBook)
          {
              string name = pair.Key;
              string phoneNumber = pair.Value;
          }
  
  
          string x = Console.ReadLine();
          if(!phoneBook.ContainsKey(x))
          {
              Console.WriteLine("Not Found");
          }
          else
          {
              string result = phoneBook[x];
              Console.Write(x);
              Console.Write("=");
              Console.Write(result);
          }
      }
  }
  
  
  Error message:
  
      Unhandled Exception:
      System.ArgumentNullException: Value cannot be null.
      Parameter name: key
        at System.Collections.Generic.Dictionary2[TKey,TValue].FindEntry (TKey key) &lt;0x7fb28d7c9320 + 0x0023c&gt; in &lt;3833a6edf2074b959d3dab898627f0ac&gt;:0 
        at System.Collections.Generic.Dictionary2[TKey,TValue].ContainsKey (TKey key) &lt;0x7fb28d7c8cd0 + 0x00009&gt; in &lt;3833a6edf2074b959d3dab898627f0ac&gt;:0 
        at Solution.Main (System.String[] args) [0x00096] in solution.cs:30 
      [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Value cannot be null.
      Parameter name: key
        at System.Collections.Generic.Dictionary2[TKey,TValue].FindEntry (TKey key) &lt;0x7fb28d7c9320 + 0x0023c&gt; in &lt;3833a6edf2074b959d3dab898627f0ac&gt;:0 
        at System.Collections.Generic.Dictionary2[TKey,TValue].ContainsKey (TKey key) &lt;0x7fb28d7c8cd0 + 0x00009&gt; in &lt;3833a6edf2074b959d3dab898627f0ac&gt;:0 
        at Solution.Main (System.String[] args) [0x00096] in solution.cs:30
  </code></pre>