Javed Iqbal

Javed Iqbal

  • NA
  • 21
  • 4.5k

Dictionary keys printing problem

Sep 15 2014 3:47 AM
Why is this code printing the same 'key' once only?
  Dictionary<int,string> dictionary = new Dictionary<int,string>();
          var keys=new List<string>();
          try
          {
              dictionary.Add(5, "javed");
              dictionary.Add(5, "khan");
              dictionary.Add(5, "javed");

          }
          catch (ArgumentException)
          {
              Console.WriteLine("Key/Value pair already used");

          }

          finally
          {

              foreach (int key in dictionary.Keys)
              {
                  Console.WriteLine(key);

              }



          }


Answers (1)