Fields
Whereas methods delineate the far-left end of the code-data spectrum, fields are on the far-right end. Fields serve as the data storage associated with a class or a struct (static fields) or instances thereof (instance fields).
Fields are variables that are declared within a class or struct definition and can have access modifiers controlling their access. Usually, fields are declared as private or protected as a matter of encapsulation, an object-oriented technique explained in Chapter 14, “Object-Oriented Programming.” By doing so, it’s possible to evolve the internal data structure of a class or struct without breaking users of the type. Properties can be used as a convenient way to access fields, while retaining the ability to change ...
Get C# 5.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.