Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Search Your Question

Friday, April 25, 2008

How do class property members work in C#?

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:

Archives