Function Parameters

This lesson covers function parameters and explains why parameters are always copied.

Function parameters #

Some of the concepts of this chapter have already appeared earlier in the course. For example, the ref keyword that we saw in the foreach loop lesson was making actual elements available in foreach loops as opposed to copies of those elements.

Additionally, we covered the const and immutable keywords and the differences between value types and reference types in previous chapters. We have written functions that produced results by making use of their parameters. For example, the following function uses its parameters in a calculation:

double weightedAverage(double quizGrade, double finalGrade) {
    return quizGrade * 0.4 + finalGrade * 0.6; 
}

That function calculates the average grade by taking 40% of the quiz grade and 60% of the final grade. Here is how it may be used:

Get hands-on with 1400+ tech skills courses.