CHAPTER 10Indexers and Properties

This chapter examines two special types of class members that have a close relationship to each other: indexers and properties. Each expands the power of a class by enhancing its integration into C#’s type system and improving its resiliency. Indexers provide the mechanism by which an object can be indexed like an array. Properties offer a streamlined way to manage access to a class’ instance data. They relate to each other because both rely upon another feature of C#: the accessor.

Indexers

As you know, array indexing is performed using the [ ] operator. It is possible to define the [ ] operator for classes that you create, but you don’t use an operator method. Instead, you create an indexer. An indexer allows ...

Get C# 4.0 The Complete Reference 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.