A property may have a get and/or a set associated with it. Within a set accessor block, C# automatically provides a variable called 'value' which holds the new value to which the property can be set.
A property with a get and set accessor for the int variable age would be defined as follows:
To set the value of age in object instance p to the new value of 34, :
public int Age
{
get { return age; }
set { age = value; }
}
No comments:
Post a Comment