title: Duplicate key in Dictionary
body: <p>I am trying to populate a <code>dictionary</code> with values from two files, the first file <code>caveConnections</code> populates the first key value of the dictionary. the second key value is populated <code>connectionWeights</code> the file contents are as follows</p>
  
  <p><code>caveConnections</code></p>
  
  <pre><code>4
  4 5
  5 6 7
  1 5 6
  2 3 4
  3 4
  3
  </code></pre>
  
  <p><code>connectionWeights</code></p>
  
  <pre><code>2
  8 3
  2 14 5
  7 6 11
  2 11 6
  14 1
  1
  </code></pre>
  
  <p>the code that carries this out is as follows;</p>
  
  <pre><code>Graph g = new Graph();
  for (int i = 0; i &lt;= totalNumberOfCaves; i++)
  {
      string ConnectedCaves = @"D:\UNI\Year 5\AI - SET09122\SET09122 - CW1\WriteConnectedCaves.txt";
      string[] lines = File.ReadAllLines(ConnectedCaves);
      //adds the values to the graph
      for (int k = 0; k &lt; lines.Length; k++)
      {
         string[] ints = lines[i].Split(' ');
         Dictionary&lt;int, int&gt; dict = new Dictionary&lt;int, int&gt;();
         for (int j = 0; j &lt; ints.Length; j++)
         {
              if (!dict.ContainsKey(int.Parse(ints[i].Trim())))
              {
                  dict.Add(int.Parse(ints[i].Trim()), int.Parse(connectionweight.Pop()));
              }
          }
          Console.Write(dict);
          g.add_vertex(k+1, dict);
      }
  }
  </code></pre>
  
  <p>as far as I can see there shouldn't be an issue but I am getting the following error when running;</p>
  
  <blockquote>
    <p>Unhandled Exception: System.ArgumentException: An item with the same key has already been added.
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary<code>2.Insert(TKey key, TValue value, Boolean add)
       at System.Collections.Generic.Dictionary</code>2.Add(TKey key, TValue value)
       at Djikstras_algo.Program.Main(String[] args) in D:\UNI\Year 5\AI - SET09122\SET09122 - CW1\tests\Djikstras_algo\Djikstras_algo\Program.cs:line 186
    Blockquote</p>
  </blockquote>
  
  <p>I'm unsure as to why this error is occurring. if its useful the full project code can be found here - <a href="https://www.pastiebin.com/5c03b94888ef0" rel="nofollow noreferrer">Djikstras_Project</a></p>
  
  <p>Any suggestion on why this isn't working would be great.</p>
  
  <p>Thanks</p>