class Address { protected string city; public string City { get { return city; } } protected string zipCode; public string ZipCode { get { return zipCode; } set { // Validate value against some datastore. zipCode = value; // Update city based on validated zipCode. } } }
Inheriting Properties
Like methods, a property can be decorated with the virtual, override, or abstract modifiers I covered in Chapter 6, "Methods." This enables a derived class to inherit and override properties just as it could any other member from the base class. The key issue here is that you can specify these modifiers only at the property level. In other words, in cases where you have both a getter method and a setter method, if you override one, you must override both.