4.6. Properties

Properties are like smart fields. A property generally has a private data member accompanied by accessor functions and is accessed syntactically as a field of a class. Although properties can have various access levels, the most common and useful access level is public access. You should expose properties instead of public fields from your components. Properties can be versioned, they allow data hiding, and the accessor methods can execute additional logic. Generally, because of JIT optimizations, properties are no more expensive than fields. Properties should be stateless with respect to other properties. They can be set in any order. Properties are discussed further in Chapter 17.

The following keywords are applicable to properties: ...

Get .NET for Java Developers: Migrating to 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.