About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Declaring and Using Properties

Like most other members, properties can have access modifiers, can be associated with the type (static) or an instance thereof, and can support other object-oriented modifiers that are discussed in Chapter 14. Their characteristic syntactic surface consists of one or two accessors, which are code blocks that deal with get or set operations:

class Person{    private string _name;    private int _age;    public string Name    {        get { return _name; }        set { _name = value; }    }    public int Age    {        get { return _age; }        set { _age = value; }    }}

In the preceding example, both Name and Age are properties. Each of those properties has a get and a set accessor, both of which are publicly ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required