Variable-length argument lists allow you to create methods that receive an arbitrary number of arguments. A one-dimensional array-type argument preceded by the keyword params in a method’s parameter list indicates that the method receives a variable number of arguments with the type of the array’s elements. This use of a
params modifier can occur only in the last entry of the parameter list. While you can use method overloading and array passing to accomplish much of what is accomplished with variable-length argument lists, using the
params modifier is more concise.
Figure 8.22 demonstrates method
Average (lines 8–17), which receives a variable-length sequence of
doubles (line 8). C# treats the variable-length ...