title: adding items to a list in a dictionary
body: <p>I'm trying to put values into a dictionary dependent on the key...  For example, if in a list of keys at the index 0 there is a letter "a". I want to add the val with index 0 to a list inside of a dictionary with the key "a" ( dictionary (key is "a" at index 0 , val at index 0) ... dictionary (key is "b" at index 2 , val at index 2)) </p>
  
  <p>I'm expecting an output like this:</p>
  
  <blockquote>
    <p>in listview lv1: 1,2,4 in listview lv2: 3,5</p>
    
    <p>what I'm getting is 3,4,5 in both listviews</p>
  </blockquote>
  
  <pre><code>List&lt;string&gt; key = new List&lt;string&gt;();
  List&lt;long&gt; val = new List&lt;long&gt;();
  List&lt;long&gt; tempList = new List&lt;long&gt;();
  Dictionary&lt;string, List&lt;long&gt;&gt; testList = new Dictionary&lt;string, List&lt;long&gt;&gt;();
  
  key.Add("a");
  key.Add("a");
  key.Add("b");
  key.Add("a");
  key.Add("b");
  val.Add(1);
  val.Add(2);
  val.Add(3);
  val.Add(4);
  val.Add(5);    
  
  for (int index = 0; index &lt; 5; index++)
  {
  
      if (testList.ContainsKey(key[index]))
      {
          testList[key[index]].Add(val[index]);
      }
      else
      {
          tempList.Clear();
          tempList.Add(val[index]);
          testList.Add(key[index], tempList);
      }
  }    
  lv1.ItemsSource = testList["a"];
  lv2.ItemsSource = testList["b"];
  </code></pre>
  
  <p>Solution:</p>
  
  <p>replace the else code section with :</p>
  
  <p>testList.Add(key[index], new List { val[index] });</p>
  
  <p>thx everybody for your help =)</p>