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

Indexers: Using Objects Like Arrays

As we have seen earlier, an array contains many useful built-in methods and properties, such as Sort and Length. Sometimes, however, we need other abilities than those offered by the Array class. Perhaps we want an array that can find the sum and the average of its elements or display their values on a graphical user interface in a specific style. In those cases, we can write a class that essentially is an array (it would likely have an array or another collection as an instance variable) but with the extra functionality included.

Remember that to access a specific element of an array, we insert the element's index number in square brackets after the name of the array as follows:

...accounts[4]...

So if an ...

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