When you say return Quiz1
inside of the get
ter, you're recursively calling the get
ter over and over again.
Auto-Implemented Properties (e.g. public double Quiz1 { get; set; }
) provide a hidden field in which the property's value is actually stored.
When implementing traditional (non-auto) get
and set
methods for a property, there is no auto-generated backing field.
Thus, you typically need to add a backing variable as well:
private double m_quiz1;
public double Quiz1
{
get { return m_quiz1; }
set
{
if (value > 0 && value < 101)
{
m_quiz1= value;
}
else
{
m_quiz1= 0;
}
}
}
See also: