Lecture overview -- Keyboard shortcut: 'u'  Previous page: Indexers [Section] -- Keyboard shortcut: 'p'  Next page: Associative Arrays -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 13 : 29
Object-oriented Programming in C#
Data Access, Properties, and Methods
Indexers in C#

Indexers are a kind of properties. Indexers let you use array notation on objects that are instances of your own classes.

Indexers allow access to data in an object with use of array notation

/user/normark/oop-csharp-1/sources/c-sharp/indexers-abc/1/a.csA Class A with an indexer. This program is explained

This is a simple and somewhat artificial example of the use of indexers. It is illustrated how three individual variables d, e, and f in class A can be accessed as a[1], a[2], a[3], where a is an instance of class A.

/user/normark/oop-csharp-1/sources/c-sharp/indexers-abc/1/b.csA client of A which uses the indexer of A. This program is explained

/user/normark/oop-csharp-1/sources/c-sharp/indexers-abc/1/outputOutput from Main in class B.

/user/normark/oop-csharp-1/sources/c-sharp/ecma-language-specification/bit-array/bitarray.csThe class BitArray. This program is explained

This is example shows a fine and realistic use of an indexer. The indexer accesses the individual bits in a bit array. The bit array is represented as a (relatively small) array of 32 bit integers. This example is taken from the C# language specification. Please consult the text book version for an explanation of the details.

/user/normark/oop-csharp-1/sources/c-sharp/ecma-language-specification/bit-array/client.csA client of class BitArray. This program is explained