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 ...

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.