O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Properties

Even though a property presents itself as a public instance variable to the world outside the class where it is defined, it is still implemented somewhat like a method inside the class (it has an ability to execute statements). This double life makes them highly suited for replacing accessor and mutator methods. Our path to understanding properties and why they provide more consistent, clearer, and intuitive code begins with a look at accessor and mutator methods.

Properties Versus Accessor and Mutator Methods

According to the encapsulation principle, discussed in Chapter 3, instance variables of an object must be hidden from source code written outside the object. In C#, this is typically implemented by declaring all instance variables ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required