O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Arrays As Return Values from Methods

C# allows a method to return an array object reference back to the caller. Figure 10.12 shows the relevant parts of a source program making use of this feature. Two methods are defined here—Main (lines 5–40) and GetTenRandomNumbers (lines 50–71). The latter will, when called, return a reference to an array containing ten random numbers. These numbers could be used for various mathematical analyses (irrelevant for this demonstration and therefore not shown) performed in the Main method.

Figure 10.12. Returning a reference to an array object of base type int.

Recall that the return type for a method is specified ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required