- Pascal case: GreenButtonType.
- Camel case: myInt
This is a general example of a property.
private int propertyName public int PropertyName {This is the minimum code you need to implement for both readable and writeable properties. The identifier value is provided by the compiler to represent the value that the property is assigned. You can add more code within the get or set functions. A common use is to limit the range of values.
get { return propertyName;}
set { propertyName=value;}
}
public int SpeedHere an exception is raised if a property is assigned with a value outside the acceptable range. You could just coerce the speed within this range but raising an exception like this tells you the developer that something went wrong in the calling code and helps you fix the code before you ship it. We'll cover exceptions in more detail in a future tutorial.
{
get { return speed; }
set {
if (speed <0 || speed > 70)
throw new Exception("Speed outside range 0..70") ;
speed = value;
}
}
On the next page : About Object Methods and Constructors

