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

Adjusting for the Zero-Based Array Index

The index of any array commences at 0; this cannot be altered. Occasionally, however, you might want a program to give the user the impression that a different and more suitable numbering scheme is being applied to a collection of data items. For example, it might often be more convenient to think of the first item in a collection as having index 1, rather than index 0. By making appropriate adjustments in the source code, you can accomplish this objective.

As an example, let's adjust Listing 10.2 to give the user the impression that the first account balance is number 1 (instead of 0) and the last number is 5 (instead of 4). First, we need to locate all lines of code that prints the index (the variable ...

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