I\'m not sure why i\'m getting this error to be honest.
private int hour
{
get;
set
{
//make sure hour is positive
if (value <
You cannot provide your own implementation for the setter when using automatic properties. In other words, you should either do:
public int Hour { get;set;} // Automatic property, no implementation
or provide your own implementation for both the getter and setter, which is what you want judging from your example:
public int Hour
{
get { return hour; }
set
{
if (value < MIN_HOUR)
{
hour = 0;
MessageBox.Show("Hour value " + value.ToString() + " cannot be negative. Reset to " + MIN_HOUR.ToString(),
"Invalid Hour", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
//take the modulus to ensure always less than 24 hours
//works even if the value is already within range, or value equal to 24
hour = value % MAX_HOUR;
}
}
}