Indexers

In indexers, accessors are used for indexing arrays. An indexer is an element that enables instances of classes, structs, and other objects to be indexed or categorized in the same way as in arrays. An indexer can be written for an object that can be linked to an array. In properties, accessors are used for the get and set actions. An indexer enables programmers to use the syntax of an array to access the class that encapsulates the array. You also can use an indexer to access classes that encapsulate collection-like functionality. Declaring an indexer enables you to create classes that are like virtual arrays.

Note

Declaring an indexer in C# is comparable with declaring a [] operator in C++. Indexers, however, are more flexible. You ...

Get Special Edition Using C# 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.