public class PropertyHolder
{
private int someProperty = 0;
public int SomeProperty
{
get
{
return someProperty;
}
set
{
someProperty = value;
}
}
public int SomePropertyOtherLocalStyle
{
get
{
return _somePropertyOtherLocalStyle;
}
set
{
_somePropertyOtherLocalStyle= value;
}
}
}
Note - the variable is not accessible directly as it is private so needs a get and set functionality.
also - the property is the same name as the varible except for the fact it has a capitalized first letter.
also - value is the implicit name of incoming value. Type will be int in this case - as it is whatever is stated in property declaration.
traditional OO style would have had 2 distinct methods with 2 diff names to access the
private variable - prob getSomeProperty and setSomeProperty. This approach only the single property name needs to be referenced. For read only just omit the set statement.
You could program your own methods to acheive this but you would lose the functionality to use objects.property syntax. Get and Set are really a shortcut to allow that syntax on non trivial members variables.