Properties in C#

A property is similar to that of variable in terms of usage, but it is much more than a variable. Features of properties can be made writeonly or readonly.

Properties can be executed whenever a value is assigned or value is read.

When a value is assigned to the properties set block will be executed and the value assigned will be stored in a predefined variable called value. This predefined variable exists internally in set block.

Whenever a value is read from the properties, get block gets executed which is used to return a value.
Write only properties:

In this method a property can be used only to write the value but cannot read the value.

ReadOnly only Properties:

In this method a property can be used only to read the value but it cannot be used to write the value.

For Example:

Program
Figure 1: Example

program 2
Figure 2: Example

Output:

10

Next Recommended Reading Abstract Property In C# Language