There are times when we may want a property to be read-only – such that it can’t be
changed.
This is where read-only properties come into the picture. A Read Only property is one
which includes only the get accessor, no set accessor.
Example:
Similar to read-only properties there are also situations where we would need
something known as write-only properties. In this case the value can be changed
but not retrieved. To create a write-only property, use the WriteOnly keyword and
only implement the set block in the code as shown in the example below.
Advertisement
changed.
This is where read-only properties come into the picture. A Read Only property is one
which includes only the get accessor, no set accessor.
Example:
public readOnly int empid
{
get
{
return empid;
}
}
{
get
{
return empid;
}
}
Similar to read-only properties there are also situations where we would need
something known as write-only properties. In this case the value can be changed
but not retrieved. To create a write-only property, use the WriteOnly keyword and
only implement the set block in the code as shown in the example below.
public writeOnly int e
{
set
{
e = value
}
}
{
set
{
e = value
}
}
Advertisement
0 comments:
Post a Comment