Writing the Main() code
How do you make use of this? Well, let's go into the Main()
code block and type the following:
var (sum, average) = Summarize(new double[] { 1, 4, 5, 3, 6 });
If you hover over Summarize
and look at the tooltip, you'll observe that it says double sum, double average
:

Figure 4.3: Mouse hover tooltip
This confirms that our function is capable of returning two values, not only one value, so it's already more flexible and powerful. We then just send our Summarize
function a new array containing some random values that we'll use for testing. So, Summarize
takes an array and finds the sum and average. These values are returned as a tuple, then saved to the sum
, average
variable below. After that, they're accessible; you can make use of them. Let's do this now by printing the result. On the next line, type the following:
WriteLine($"Sum={sum} \nAverage={average}");
As before, we have using static System.Console
at the top so that we can use WriteLine
. Of course, this will simply...