title: C# Recursion to get the proper count
body: <p>OK so today is one of those days that my mind cannot work properly.<br>
  I cannot make this to work (:</p>
  
  <pre><code>class Program
  {
      static private List&lt;KeyValuePair&lt;int, double&gt;&gt; _list;
      static protected List&lt;KeyValuePair&lt;int, double&gt;&gt; list
      {
          get
          {
              if (_list == null)
              {
                  _list = new List&lt;KeyValuePair&lt;int, double&gt;&gt;();
  
                  _list.Add(new KeyValuePair&lt;int, double&gt;(1, 11.60));                                        
                  _list.Add(new KeyValuePair&lt;int, double&gt;(2, 11.20));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(3, 13.00));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(4, 13.60));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(5, 15.90));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(6, 16.10));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(7, 19.10));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(8, 19.10));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(9, 19.10));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(10, 21.00));
                  _list.Add(new KeyValuePair&lt;int, double&gt;(11, 23.00));
              }
  
              return _list;
          }
      }
  
      static void Main(string[] args)
      {
          Program p = new Program();
  
          int value = 27;
          double d = p.GetCost(value);
      }
  
      public double GetCost(int tot)
      {
          double cost = 0;
          if (tot &lt; 1)
              return list[tot-1].Value;
  
          cost += GetCost(tot - list.Count);
          return cost;
      }        
  }
  </code></pre>
  
  <p>So conceptually, I need to set that recursion GETCOST procedure to work properly
  so that it will call itself and get the RIGHT value (the second column) from the LIST
  and add it to the recursive caller.</p>
  
  <p><strong>EXPECTED RESULTS</strong></p>
  
  <blockquote>
    <blockquote>
      <p>if the "value" is <strong>8</strong>
         the total should be <strong>$19.10</strong>
      $19.10
            from KeyParValue(8 - 19.10)</p>
      
      <p>if the "value" is <strong>12</strong>
         the total should be <strong>$36.60</strong>
      $23 + 11.60
            from KeyParValue(11 - 23.00) + KeyParValue(1 - 13.60)  </p>
      
      <p>if the "value" is <strong>27</strong> 
         the total should be <strong>$61.90</strong><br>
      $23 + $23 + $15.90; 
            from KeyParValue(11 - 23.00) + KeyParValue(11 - 23.00) + KeyParValue(5 - 15.90)  </p>
    </blockquote>
  </blockquote>
  
  <p>Thanks advanced,
  F.</p>