title: how to dynamically generate a formula and solive it by selecting multiple rows using linq
body: <p>hi guys i have an array called tblCeMaintMatrix.ToArray())  with a result of :</p>
  
  <pre><code>[0]: { xValue = 0, Operator = 43 '+' }
  [1]: { xValue = 1, Operator = 43 '+' }
  [2]: { xValue = 12, Operator = 45 '-' }
  </code></pre>
  
  <p>i made a foreach loop to solve this however i encountered some errors. I think i confused the logic for this..</p>
  
  <pre><code>foreach (var a in tblCeMaintMatrix.ToArray())
  {
      {
          value = operate((a.Operator).ToString(),a.xValue.Value );
      }
      decimal value2 = value;
  }
  
  private decimal operate(String a, Decimal value)
  {
          Decimal Value = 0;
          if (a == "+")
          {
              Value = value + value;
          }
  
          if (a == "-")
          {
              Value= value - value;
          }
  
          if (a == "*")
          {
              Value = value * value;
          }
  
          if (a == "/")
          {
              Value = value / value;
          }
  
          return Value;
      }
  </code></pre>
  
  <p>my problem is that </p>
  
  <p>a) what is does is this :</p>
  
  <p>0 + 0 = 0</p>
  
  <p>1 + 1 = 2</p>
  
  <p>12 - 12 = 0</p>
  
  <p>instead of  0 + 1 -12.</p>
  
  <p>b) it doesnt retain the value.</p>
  
  <p>how can i modify this to solve the problem? thanks</p>