title: How to return multiple values from a function in C# (ASP.NET)?
body: <p>I have a page where some products and textfields where the user enters a number. I first use JavaScript to calculate the total cost. Based on how many users they enter they get a different rate (as shown in code below). When the user types or paste a number into a textfield the function CalculateCost gets called which calls the other functions (only showing two in the example, CDCOst and DVDCost) to make sure the fields Monthly Cost and Annual Cost are displaying the correct value.      </p>
  
  <p>I of course want to do the final calculation in the code behind as well before I insert into the database. How can I achieve something similiar in C#?</p>
  
  <pre><code>function CDCost() {
                  var monthlyAmount;
                  var annualAmount;
                  var amount;
                  var users = $('#txtCD').val();
  
              if (users &gt; 0 &amp;&amp; users &lt; 100) {
                  amount = users * 14.95;
                  monthlyAmount = amount;
                  annualAmount = monthlyAmount * 12;
                  return [monthlyAmount, annualAmount];
              }
              if (users &gt;= 100 &amp;&amp; users &lt;= 250) {
                  amount = users * 12.95;
                  monthlyAmount = amount;
                  annualAmount = monthlyAmount * 12;
                  return [monthlyAmount, annualAmount];
              }
              if (users == 0) {
                  monthlyAmount = 0;
                  annualAmount = 0;
                  return [monthlyAmount, annualAmount];
              }
          }
  
  function DVDCost() {
                  var monthlyAmount;
                  var annualAmount;
                  var amount;
                  var users = $('#txtDVD').val();
  
              if (users &gt; 0 &amp;&amp; users &lt; 100) {
                  amount = users * 16.95;
                  monthlyAmount = amount;
                  annualAmount = monthlyAmount * 12;
                  return [monthlyAmount, annualAmount];
              }
              if (users &gt;= 100 &amp;&amp; users &lt;= 250) {
                  amount = users * 14.95;
                  monthlyAmount = amount;
                  annualAmount = monthlyAmount * 12;
                  return [monthlyAmount, annualAmount];
              }
              if (users == 0) {
                  monthlyAmount = 0;
                  annualAmount = 0;
                  return [monthlyAmount, annualAmount];
              }
          }
  
  
          function CalculateCost() {
              var cd = CDCost();
              var dvd = DVDCost();
  
              var monthlyCost = cd[0] + dvd[0];
              var annualCost = cd[1] + dvd[1];
  
              return [monthlyCost, annualCost];
          }
  
          $('#txtCD').bind('keyup change', function (ev) {
              var cost = CalculateCost();
              var monthly = cost[0];
              var annual = cost[1];
  
              $('#MonthlyCostSum').text(monthly);
              $('#AnnualCostSum').text(annual)
          });
  </code></pre>
  
  <p>How would I go on doing this in C#?</p>
  
  <p>Something like:</p>
  
  <pre><code>protected double CDCost()
      {
          double monthlyAmount;
          double annualAmount;
          double amount;
          double users = Convert.ToDouble(txtCD.Text);
  
          if (users &gt; 0 &amp;&amp; users &lt; 100)
      {
          amount = users * 14.95;
          monthlyAmount = amount;
          annualAmount = monthlyAmount * 12;
          return //how do I return the values here to a CalculateCost function?
      }
  
  
  }
  </code></pre>