Chapter 11. Fields, Properties, and Indexers

In This Chapter

Fields 545

An Intermezzo About Enums 558

Properties 569

Indexers 574

Having covered the code aspect of types by looking at methods in Chapter 10, we can now move on to the data aspect of types. Fields are containers for data that’s part of a type or its instances. We now discuss how to declare and use fields.

After an intermezzo about enum types—which merely are very data-centric types with symbolic names for special values—we continue our exploration with properties and indexers. Those members are closely related to the data aspect of types in that they usually provide code-based accessors to an object’s start.

Fields

Whereas methods delineate the far-left end of the code-data ...

Get C# 4.0 Unleashed 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.