Arrays and Methods

Array elements, such as accountBalances[0], as well as array object references, such as accountBalances, can be arguments in a method call, as well as return values from a method. The next few sections show you how and discuss the implications and possibilities.

Array Elements As Method Arguments

Recall that an array element, like accountBalances[0] of base type decimal, can be applied in any position of the source code where a simple variable of type decimal can be used. This also allows for array elements to be used as method arguments in method calls.

For example, the following line is a method header of the MaxAmount method specifying that method calls must provide two arguments both of type decimal.

 private static decimal ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.