The coach window needs to read player information. C# properties provide field-like access syntax while running accessor code defined by the class.
| Member | What it does |
|---|---|
| Field | Stores state in this example |
| Property | Defines accessors used when reading or assigning |
| Method | Expresses an operation called with parentheses |
A property may read a private backing field, validate a proposed value, or calculate an answer. It does not have to store a separate value itself. The following diagram pages show the notation before the technical implementation lessons.
Compare the two forms below conceptually. Do not paste them together: they show alternative interfaces.
int turns = player.GetNumberOfTurns();int turns = player.NumberOfTurns;The second line can run a get accessor even though it has no call parentheses. A property declaration determines what code runs and whether assignment is available. Looking only at the caller does not prove the member is a field.
Keep RecordTurn as an action. A NumberOfTurns property can report the result without letting callers assign arbitrary totals. A getter-only count can change later because an action changes its underlying state.