CSharp - Read-only and calculated properties

Introduction

A property is read-only if it specifies only a get accessor.

double r;

public double ReadOnlyR
{
   get { return r; }
}

It is write-only if it specifies only a set accessor.

double r;

public double R
{
   set { r = value; }
}

A property typically has a dedicated backing field to store the underlying data.

A property can be computed from other data.

For example:

double r;

public double Area
{
   get { return r * r * pi; }
}

Related Topics