title: dictionary stays the same when returning from recursion
body: <p>I have this piece of code that uses recursion to calculate the sum of something on all numbers up to limit.</p>
  
  <pre><code>static long gen(int limit, List&lt;int&gt; primes,int num,int idx,myDict dict,long sum)
      {
  
          for (int i = idx; i &lt; primes.Count; i++)
          {
              if (num * primes[i] &gt; limit || num * primes[i] &lt; 0)
              {
                  return 0;
              }
              dict.update(primes[i]);
              Console.WriteLine("{0}--&gt;{1}", num * primes[i], dict.maxv);
              gen(limit, primes, num * primes[i], i, dict, sum + dict.maxv);
          }
          return sum;
      }
  </code></pre>
  
  <p>myDict is basically a dictionary that saves it's max value and the key to that value.</p>
  
  <p>My problem is that <code>dict</code> is not changing when returning from the recursion. I mean that if for example I debug the function and in the call stack there are a few calls to this function and I try to examine the values of the variables there. <code>num</code> holds the value it should according to when it was called but dict always holds the "newest" value.</p>
  
  <p>lets take an example that in the call stack the value for <code>num</code> is currently <code>8</code> and dict currently holds the values:<code>2:(3,4)</code> the dict that we should have is this. but if I examine the previous calls in the call stack I find that in all of them dict has the same value and not the value that it had when the function was could from there.</p>
  
  <p>I think that maybe there is some conceptual idea that I'm not understanding correctly. </p>