13.12. More on Properties
Chapter 4 introduced properties as a way to get or set the value of fields that have been given private access. Properties are used as if they were public data members, but behind the scenes they make use of a special type of method called accessors. In this section we will explore a few of the nuances of properties that make them even handier and more powerful.
13.12.1. Asymmetric Accessibility
By default, the get and set accessors of a property will have the same access as was given to the property itself. For example, the following property might be defined to access the id field of the Student class:
public string Id { get { return id; } set { id = value; } }
In the previous example, the Id property is declared ...
Get Beginning C# 2008 Objects: From Concept to Code 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.