Been reading about out/ref and tuple, but for the life of me cannot figure out how to implement a way to return three (3) values (whether within same method that calculates my main value, or with separate methods). I am able to perform a calculation with one value (the main value) which deals with pricing for a service.
Here is a snippet of what I’ve done to calculate that main value:
public class Calculations
{
public decimal decFinancialAccount(QuoteData quoteData)
{
if (quoteData.StepAssetInformation.FinancialAccountDropDown
== StepAssetInformation.FinancialAccount.None)
return 0;
else if (quoteData.StepAssetInformation.FinancialAccountDropDown
== StepAssetInformation.FinancialAccount.One)
return PriceQuote.priceFinancialAccount;
else if (quoteData.StepAssetInformation.FinancialAccountDropDown
== StepAssetInformation.FinancialAccount.Two)
return (PriceQuote.priceFinancialAccount * 2);
...
else
return 0;
}
public decimal CalculateChapter7(QuoteData quoteData)
{
decimal total = PriceQuote.priceChapter7;
...
total += this.decFinancialAccount(quoteData);
return total;
}
}
The above works out great. It obviously has other decimal‘s that are added, but you get the idea.
Now, I am wanting to perform additional calculations on the CalculateChapter7 value that is returned.
The first value is a DiscountChapter7 / discount (variable in method?) price: above a certain amount, discounts are applied for every increment of 50. I got no problem listing them all out if I have to (rather than complicating things for myself). There is no set formula for the discounts, I just created an Excel sheet to visualize my discounts (see below).
The second value is a CompareChapter7 / compare (variable in method?) price: for every discounted price I offer, a comparison is made to what other’s charge for the same service. Again, there is no formula per se, I just used an Excel sheet to figure those out arbitrarily.
In addition, I’d like to (within the “discount” and “compare”) do a simple subtraction to show “savings” (calculated price – discounted price = savings) and “difference” (other attorneys charge – discounted price = difference). I imagine when I get the two values above working that these additional two would be simple.
Here is my Excel sheet (just a small snippet):

A few notes about that:
- Between 799 and 999 there are no discounts (the “rounded” column is just to bring those numbers to a 50 increment for my ease of use and are not relevant).
- The Excel formulas are pretty straightforward (fee – discounted price = savings; other attorneys charge – discounted price = difference) – which is what I am trying to attain within my code.
Can anyone provide a solid example of how to integrate the “discount” and “comparison” with my calculated price?
Thanks!
You need to create a new class that will contain all the return values. If it’s not going to be used anywhere else, you could nest the class inside the Calculations class as follows, but that’s up to you:
When you do it this way, all three return values are packaged up into a single object which is then returned. Each time you call the method, it creates a new Result object and populates it with all the values for that invocation of the method. So, to read the returned values after calling the method, you would need to read each property out of the returned object. For instance you could do something like this: