Summary

After our coverage of the code aspects of types in Chapter 10, “Methods,” we aimed our discussion at their data aspect in this chapter. Both aspects are quintessential in the definition of types. Nonetheless, some members of types don’t fall in just one category; for example, properties and indexers.

First, you explored the extreme end of a type’s state spectrum by covering fields, which act as containers for state associated with a type or an instance of a type. You learned how to declare and initialize fields, also covering the notion of read-only fields that are immutable outside what’s known as the constructor. At first sight, constants are similar to read-only fields, so you learned about some important differences.

After talking ...

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.